0
在下面的代碼中,我創建了一個字符串數組,並拆分字符串以去除ID。取而代之,我想要關聯數組,以便我可以從數組中選擇項目的ID。誰能幫忙!Android ListView獲取項目ID
String[] data={"12__Item 1","14__Item 2","34__Item 3","56__Item 4"};
lv = (ListView)findViewById(R.id.leaning_path_list_view);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,R.layout.learning_path_single_row,R.id.textView,data);
lv.setAdapter(adapter);
lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
String item =(String)parent.getItemAtPosition(position);
String[] parts = item.split("__");
Toast.makeText(getApplicationContext(),
"ID: " + parts[0]+" Title: " + parts[1], Toast.LENGTH_LONG)
.show();
}
});
你的代碼沒有開始新的活動,因爲startActivity(i);已被註釋掉 – Blackbelt
對不起,我已更新問題 –
請編輯您的問題,以清楚地顯示您的問題。 –