检索从多选ListView中选定的项目多选、项目、ListView

2023-09-06 16:59:50 作者:Lonely patients(孤独患者)

我目前正在执行一个多选的ListView 我的Andr​​oid应用程序。我的目标是检索所选项目的 ArrayAdapter 相关联的的ListView 点击搜索按钮时。

我目前难倒如何做到这一点,我已经找到的东西在网上,如尝试设置 MultiChoiceModeListener ,但这似乎并没有拿出作为一个选项在的Eclipse 。我使用谷歌API S(10级),的Andr​​oid 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){}        });    }} 

解决方案

使用方法 getCheckedItemPosition()

C winform listview 选中的复选框排序

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 APIs(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().