2012-12-24 119 views
1

我在我的應用程序中使用android.R.layout.simple_list_item_checked作爲listview。但我無法選中一個列表項作爲檢查。無法在android.R.layout.simple_list_item_checked中選擇項目

這裏是代碼

ArrayAdapter<String> arrayadapter = new ArrayAdapter<String>(Selectfarmer.this, android.R.layout.simple_list_item_checked,arraylistfarmer); 
    lvselectfarmer.setAdapter(arrayadapter); 
+0

你用過的setOnItemClickListener ?? –

回答

2

我發現它,你需要使用

lvselectfarmer.setChoiceMode(ListView.CHOICE_MODE_SINGLE); 
0

嘗試下面的代碼,

ArrayAdapter<String> adapter=new ArrayAdapter<String>(this, android.R.layout.simple_list_item_multiple_choice,arraylistfarmer); 
lvselectfarmer.setAdapter(arrayadapter); 
int len = lvselectfarmer.getCount(); 
SparseBooleanArray checked = lvselectfarmer.getCheckedItemPositions(); 
for (int i = 0; i < len; i++) 
if (checked.get(i)) { 
    String item = lvselectfarmer.get(i); 
    /* do whatever you want with the checked item */ 
} 
0
@Override 
protected void onListItemClick(ListView l, View v, int position, long id) { 
    CheckedTextView textview = (CheckedTextView)v; 
    textview.setChecked(!textview.isChecked()); 
}