public class MainActivity extends Activity implements OnItemClickListener{
ArrayAdapter<String> arr;
ListView list;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
String[] st = {"aa","bb","cc"};
list = (ListView)findViewById(R.id.listView1);
arr = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_multiple_choice, st);
list.setAdapter(arr);
list.setOnItemClickListener(this);
}
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
// TODO Auto-generated method stub
list.setItemChecked(arg2, true);
}
}
这是非常简单的代码,但仍然没有检查框。这意味着我不明白。
答案 0 :(得分:0)
我找到了所有问题的问题! (并且有很多)
问题出在我做xml的时候
<ListView
android:id="@+id/stationsList1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
**android:choiceMode="multipleChoice"**
&GT; 忘记了......