检索从多选ListView中选定的项目 [英] Retrieving the selected items from a multi-select ListView
问题描述
我目前正在执行一个多选的ListView
我的Android应用程序。我的目标是检索所选项目的 ArrayAdapter
相关联的的ListView
点击搜索按钮时。
我目前难倒如何做到这一点,我已经找到的东西在网上,如尝试设置 MultiChoiceModeListener
,但这似乎并没有拿出作为一个选项在的Eclipse
。我使用谷歌API
S(10级),的Android 2.3.3
等价的。这里是code我到目前为止有:
公共类FindPlace延伸活动{ 公共FindPlace(){} @覆盖
保护无效的onCreate(捆绑savedInstanceState){
super.onCreate(savedInstanceState);
的setContentView(R.layout.list_places);
按钮搜索=(按钮)findViewById(R.id.search);
。的String [] =类别getResources()getStringArray(R.array.Categories);
ArrayAdapter广告=新ArrayAdapter(这一点,android.R.layout.simple_list_item_multiple_choice,类别);
最终的ListView列表=(ListView控件)findViewById(R.id.List);
list.setAdapter(广告);
list.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
list.setOnItemClickListener(新OnItemClickListener(){
@覆盖
公共无效onItemClick(适配器视图<>母公司,观景,INT位置,长的id){} });
}
}
使用方法<一个href=\"http://developer.android.com/reference/android/widget/AbsListView.html#getCheckedItemPositions%28%29\"相对=nofollow> getCheckedItemPosition()
。
I am currently implementing a multi-select ListView
for my android app. My aim is to retrieve the selected items from the ArrayAdapter
associated with the ListView
when clicking the search button.
I am currently stumped on how to do this, I have found stuff online such as trying to set a MultiChoiceModeListener
, but this does not seem to come up as an option in Eclipse
. I am using Google API
s(level 10), Android 2.3.3
equivalent. Here is the code I have so far:
public class FindPlace extends Activity {
public FindPlace() {}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.list_places);
Button search = (Button) findViewById(R.id.search);
String[] categories = getResources().getStringArray(R.array.Categories);
ArrayAdapter ad = new ArrayAdapter(this,android.R.layout.simple_list_item_multiple_choice,categories);
final ListView list=(ListView)findViewById(R.id.List);
list.setAdapter(ad);
list.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
list.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) { }
});
}
}
Use the method getCheckedItemPosition()
.
这篇关于检索从多选ListView中选定的项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!