Thursday, February 13, 2014

Why listview's ID must be "@ + id / android: list"


            
And can not be "@ + id/list1234"

A change on the error.


Layout code
 

android: orientation = "vertical"
android: layout_width = "fill_parent"
android: layout_height = "fill_parent"
>

android: id = "@ + id/list1234" android: layout_width = "fill_parent"> ;








 
package com.ListView;

import java.util.ArrayList;
import java.util.HashMap;

import android.app.ListActivity;
import android.os.Bundle;
import android.widget.SimpleAdapter;

public class ListView extends ListActivity {
/ ** Called when the activity is first created. * /
@ Override
public void onCreate (Bundle savedInstanceState) {
super.onCreate (savedInstanceState);
setContentView (R.layout.main);

/ * Generate dynamic array * /
ArrayList > list1 = new ArrayList > ();
/ * Generate the map * /
HashMap map1 = new HashMap ();
HashMap map2 = new HashMap ();
HashMap map3 = new HashMap ();
/ * Put to map value * /
map1.put ("username", "123");
map1.put ("userip", "10.143.107.58");

map2.put ("username", "234");
map2.put ("userip", "10.143.105.1");

map3.put ("username", "345");
map3.put ("userip", "10.143.106.131");
/ * Add a map to the list array * /
list1.add (map1);
list1.add (map2);
list1.add (map3);
/ * Create the adapter * /
SimpleAdapter listadapter = new SimpleAdapter (this, list1, R.layout.user, new String [] {"username", "userip"}, new int [] {R.id.textView2, R.id.textView1}); < br />/ * Set the adapter * /
setListAdapter (listadapter);
}
}

Reply:
You get rid of the figures, try! Generated by id with a number in it will have problems in R.java
Reply:
Can be "@ + id/list1234"
But the program will need to change it

The default setListAdapter (adapter)
It is using the system default id must be "@ + id / android: list"

When a custom id, the program can not be directly setListAdapter (adapter);
Changes:
Program:
ListView list = (ListView) findViewById (R.id.list1234);
...
....
list.setListAdapter (adapter)


Reply:
Well, I immediately try.
Reply:
ListActivity default on the binding of this listview ID (and only this one listview).

ID you want to use the other can be used directly Activity.
Reply:
No wonder when I changed the other ID, are not checked.
Reply:
I heard my knot posted?
Reply:
For more detailed information see:

Android's ListActivity: layout and data binding
http://blog.csdn.net/prince58/archive/2011/04/25/6362284.aspx
Reply:
I would like to ask the landlord to the ListView extend ListActivity is automatically generated or handwritten ah? If it is automatically generated should be how to get ah? How is my new default inherited Activity! ! ! (Do not spray rookie Wang)
Reply:
reference to the 8th floor Wuhuixia8511191 reply:
I would like to ask the landlord to the ListView extend ListActivity is automatically generated or handwritten ah? If it is automatically generated should be how to get ah? How is my new default inherited Activity! ! ! (Do not spray rookie Wang)
Handwritten

No comments:

Post a Comment