【发布时间】:2014-03-18 21:03:05
【问题描述】:
我有一个带有 CheckBox 和一些 Textview 的 Listview,我正在尝试获取所有选中的项目。我正在使用 SimpleAdapter,但找不到任何有用的教程。有什么办法可以用 SimpleAdapter 做到这一点?
【问题讨论】:
-
您实际上可以分享一些您编写的代码,以便我们了解您的位置;
标签: android listview simpleadapter
我有一个带有 CheckBox 和一些 Textview 的 Listview,我正在尝试获取所有选中的项目。我正在使用 SimpleAdapter,但找不到任何有用的教程。有什么办法可以用 SimpleAdapter 做到这一点?
【问题讨论】:
标签: android listview simpleadapter
您可以像这样显示列表视图的选中项:
当列表视图项目被选中时,它会将项目附加到 Textview 并在项目未选中时删除。
ArrayList<String> selectedNames = new ArrayList<String>();
//Initialise selctnts in onCreate().
selctnts=(TextView)findViewById(R.id.selectedtagcontact);
public class CheckBoxClick implements AdapterView.OnItemClickListener {
int listlength;
@Override
public void onItemClick(AdapterView<?> arg0, View view, int position, long id) {
CheckedTextView ctv = (CheckedTextView) view;
String item = adapter.getItem(position);
if (ctv.isChecked()) {
ctv.setChecked(true);
selectedNames.add(ctv.getText().toString());
selctnts.append(item+", ");
} else {
ctv.setChecked(false);
selectedNames.remove(ctv.getText().toString());
listlength=selectedNames.size();
selctnts.setText("");
for(int l=0;l<listlength;l++)
selctnts.append(selectedNames.get(l)+", ");
}
}
}
【讨论】: