我正在使用帶List的onItemClickListener()。我想傳遞點擊的項目的名稱,並將任意數字傳遞給列表的下一個實例。如何才能做到這一點? 編輯:這裏是類:onItemClickListener(),如何傳遞點擊項目的數據?
public class ListViewA extends Activity{
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
ListView lv= (ListView)findViewById(R.id.listview);
// create the grid item mapping
String[] from = new String[] {"col_1"};
int[] to = new int[] {R.id.item2};
// prepare the list of all records
List<HashMap<String, String>> fillMaps = new ArrayList<HashMap<String, String>>();
for(int i = 0; i < 10; i++){
HashMap<String, String> map = new HashMap<String, String>();
map.put("col_1", "col_1_item_" + i);
fillMaps.add(map);
lv.setOnItemClickListener(onListClick);
}
// fill in the grid_item layout
SimpleAdapter adapter = new SimpleAdapter(this, fillMaps, R.layout.grid_item, from, to);
lv.setAdapter(adapter);
}
private AdapterView.OnItemClickListener onListClick=new AdapterView.OnItemClickListener(){
public void onItemClick(AdapterView<?> parent,View view, int position, long id)
{
Intent i=new Intent(ListViewA.this,ListViewA.class);
startActivity(i);
}
};
}
請提供一些代碼,以便我們可以幫助你。你使用什麼類型的適配器?您是否使用自定義適配器? – Reda 2013-03-16 08:42:08
請添加更多相關答案的詳細信息。發佈一些代碼片段以獲得更好的幫助。 – Raj 2013-03-16 08:42:23
請添加您的itemclick方法。 – 2013-03-16 08:45:49