2013年7月24日星期三

Android How to get the ListView is clicked entry value it?

My ListView is as follows:
Name Student ID achievements
aaa 111 99
bbb 222 95
data types are String type, ListView data through SimpleAdapter bound to above.
What I want to get learn how to change numbers and results obtained it?
------ Solution ---------------------------------------- ----
get to click on the line, and then what you put inside listView data, then how to remove it.
------ Solution ---------------------------------------- ----
can do a data corresponding pojo class set out as Student.java name, student number, the achievement of the private property set, get, override toString method

public class ListViewTest extends Activity {
private ListView lv;
private List stus;

@ Override
protected void onCreate (Bundle savedInstanceState) {
/ / TODO Auto-generated method stub
super.onCreate (savedInstanceState);
stus = new ArrayList ();
stus.add (new Student (1001, "zhangsan", 20,85));
stus.add (new Student (1002, "lisi", 21,87.5));
stus.add (new Student (1003, "wangwu", 22,88));
stus.add (new Student (1004, "zhaoliu", 20,75));
stus.add (new Student (1005, "qianqi", 21,97.5));
stus.add (new Student (1006, "liuba", 22,68));

setContentView (R.layout.list_view_test);

lv = (ListView) findViewById (R.id.list_view_01);

List > data = new ArrayList > ();
for (int i = 0; i Map map = new HashMap ();
map.put ("s_id", stus.get (i). getId ());
map.put ("s_name", stus.get (i). getName ());
map.put ("s_age", stus.get (i). getAge ());
map.put ("s_score", stus.get (i). getScore ());
data.add (map);
}

SimpleAdapter adapter = new SimpleAdapter (this, data, R.layout.list_view_item_02, new String [] {"s_id", "s_name", "s_age", "s_score"}, new ; int [] {R.id.s_id_text_2, R.id.s_name_text_2, R.id.s_age_text_2, R.id.s_score_text_2});
lv.setAdapter (adapter);

lv.setOnItemClickListener (new OnItemClickListener () {

@ Override
public void onItemClick (AdapterView arg0, View arg1, int arg2,
long arg3) {
Intent it = new Intent (ListViewTest.this, StudentDescribeActivity.class);
it.putExtra ("student", stus.get (arg2));
startActivity (it);

}

});

}


}
------ Solution ----------------------------------- ---------
the brother very thoughtful. Very recommended
------ Solution -------------------------------------- ------
typedef_god thousand words omitted here.
------ For reference only -------------------------------------- -
has found a solution with getItemAtPosition ()
------ For reference only ------------------------ ---------------
LZ · · · how to solve, posted under the code number

没有评论:

发表评论