android - 如何激活列表 Activity 中的复选标记?

标签 android listactivity android-arrayadapter checkmark

我有一个 ListActivity,它的数组适配器声明为 arrayAdapter = new ArrayAdapter<String> (this, android.R.layout.simple_list_item_checked);这显示了一堆在最右边带有复选标记的行。你能告诉我如何获得对这些复选标记的引用或如何选中/取消选中它们吗?

最佳答案

CheckedTextView 本身处理复选框。它作为 onListItemClick 处理程序中的第二个参数 (View v) 传入。因此,您可以按如下方式简化代码:

@Override
protected void onListItemClick( ListView l, View v, int position, long id)
{
  CheckedTextView textView = (CheckedTextView)v;
  textView.setChecked(!textView.isChecked());
}

关于android - 如何激活列表 Activity 中的复选标记?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2204994/

相关文章:

android - ArrayAdapter 中的 getActivity() 有时会返回 null

android - 从磁传感器获取信息

Android 滑动列表

android - 可搜索 ListView

android - 如何在适配器 View 、Android、ArrayAdapter、onCheckedChanged、OnCheckedChangeListener 中为复选框添加监听器

android - Android 中的 Spinner 和 ArrayAdapter NullPointerException

android - 如何在 Intent 中调用新 Activity 时使用变量?

android - 有什么办法可以查看图书馆源代码中的示例吗?

android - Android 应用程序中的 ExceptionInInitializerError?

android - 在 Activity 和 ListActivity 中共享相同的代码