Listview 顶部的 Android Logo

标签 android xml listview

我有一个 Activity ,它从服务器获取数据并将其添加到数组列表中。我有一个 xml 布局“list_item”。我想将 Logo 设置在该列表的顶部。但是,如果我在该 xml 文件上添加 Logo ,则 Logo 会显示在每个列表项中。但我只需要一个 Logo (在列表顶部)。

这是 Activity :

public class CampaignActivity extends ListActivity {

Button sub;
NotificationManager nm;
TextView campaign;
static final int uniqueId=12;
static InputStream is = null;

private static final String TAG_ID = "_id";
private static final String TAG_NAME = "name";
ArrayList<HashMap<String, String>> contactList = new ArrayList<HashMap<String, String>>();

@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    this.requestWindowFeature(Window.FEATURE_NO_TITLE);
    StrictMode.ThreadPolicy policy = new StrictMode.
            ThreadPolicy.Builder().permitAll().build();
            StrictMode.setThreadPolicy(policy); 
    //setContentView(R.layout.campaign);

    //campaign = (TextView) findViewById(R.id.textView1);
    //sub = (Button) findViewById(R.id.button1);

    //new CreateUser().execute();

    //sub.setOnClickListener(this);
    //nm=(NotificationManager)getSystemService(NOTIFICATION_SERVICE);
    //nm.cancel(uniqueId);

            DefaultHttpClient httpClient = new DefaultHttpClient();
            String url = "http://54.228.199.162/api/campaigns";
            try {
                String res;
                HttpGet httpget = new HttpGet(url);
                HttpResponse httpResponse = httpClient.execute(httpget);
                HttpEntity httpEntity = httpResponse.getEntity();
                is = httpEntity.getContent();
                BufferedReader reader = new BufferedReader(new InputStreamReader(
                        is, "UTF-8"), 8000);
                StringBuilder sb = new StringBuilder();
                String line = null;
                while ((line = reader.readLine()) != null) {
                    sb.append(line + "\n");
                }
                is.close();
                res = sb.toString();
                Log.d("um1", res);
                JSONArray jsonArray = new JSONArray(res);
                //campaign.setText(res);
                for (int i = 0; i < jsonArray.length(); i++) {
                    JSONObject jsonObject = jsonArray.getJSONObject(i);
                    String id = jsonObject.getString(TAG_ID);

                    String utfid = URLDecoder.decode(id, "UTF-8");
                    Constant.idusr = utfid;
                    //String name = jsonObject.getString(TAG_NAME);
                   // String utfname = URLDecoder.decode(name, "UTF-8");
                    String utfname = URLDecoder.decode(jsonObject.getString(TAG_NAME), "UTF-8");
                    Log.d("IDDDDDDD", id);
                    Log.d("Nameeeeeee", utfname);
                    HashMap<String, String> map = new HashMap<String, String>();

                    // adding each child node to HashMap key => value
                    map.put(TAG_ID, utfid);
                    map.put(TAG_NAME, utfname);
                    //Object contactList;
                    contactList.add(map);
                  }
                HttpResponse httpresponse = httpClient.execute(httpget);
                int responsecode = httpresponse.getStatusLine().getStatusCode();
                Log.d("responsenummmm", "um11111"+responsecode);
            } catch (Exception e) {
                // TODO: handle exception
                e.printStackTrace();
            };
            //this.setListAdapter(new ArrayAdapter<String>(this, R.layout.list_item, R.id.label, contactList));

            ListAdapter adapter = new SimpleAdapter(this, contactList,
                    R.layout.list_item,
                    new String[] { TAG_NAME,TAG_ID}, new int[] {
                            R.id.label, R.id.id});

            setListAdapter(adapter);

            // selecting single ListView item
            ListView lv = getListView();

            lv.setOnItemClickListener(new OnItemClickListener() {

                @Override
                public void onItemClick(AdapterView<?> parent, View view,
                        int position, long id) {
                    // getting values from selected ListItem
                    String idof = ((TextView) view.findViewById(R.id.id)).getText().toString();
                    String nameof = ((TextView) view.findViewById(R.id.label)).getText().toString();

                    // Starting new intent
                    Intent in = new Intent(getApplicationContext(), DonateActivity.class);
                    in.putExtra(TAG_NAME, nameof);
                    in.putExtra(TAG_ID, idof);
                    startActivity(in);
                }
            });
        }
}

这是 xml:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:paddingBottom="10dip"
android:paddingLeft="10dip"
android:paddingTop="10dip" >

<ImageView
    android:id="@+id/imageView1"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_alignParentTop="true"
    android:src="@drawable/firstscreenimage" />

<TextView
    android:id="@+id/id"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentRight="true"
    android:layout_below="@+id/relativeLayout1"
    android:text="bd" />

<TextView
    android:id="@+id/label"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentRight="true"
    android:layout_below="@+id/id"
    android:text="bd"
    android:textColor="#C20000"
    android:textSize="14sp"
    android:textStyle="bold" />

</LinearLayout>

这是我的问题:

problem list

但 Logo 应该是第一个,而不是每个列表项。请帮助我。

最佳答案

请删除 ImageView 并将其写出您使用的线性布局。正如你所说,只有当你需要这个 ImageView 时。除此之外,您可以做的是制作一个自定义适配器和自定义 ListView ,并修复它,仅对于位置索引 0,您需要显示 ImageView 。

关于Listview 顶部的 Android Logo ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20988130/

相关文章:

java - 将 ListView 项目 onclick 解析到另一个 Activity 并匹配 JSON 中的特定数据

android - 我如何在 Android API 级别 10 上实现带有 ListView 的 SlidingDrawer?

java - 如何一次点击执行两个操作?

android - 半屏滑动导航

php - 如何在 xsl 中使用 php 变量?

android - 如何从 R.java 读取 xml 文件

java - String.xml 包含太多项目,速度太慢

vb.net - 使 ListView FindItemWithText 匹配整个文本

php - 无需第三方服务即可同步移动应用程序和网络应用程序

android - Facebook API 2.1 - 关于邀请好友和应用范围内的用户 ID