从菜单中删除listview中的一些已检查元素

时间:2013-12-17 12:48:21

标签: android listview android-listview android-menu

我想创建一个简单的列表视图,显示我的所有文件复选框,所以它的工作方式如下,我选择一些文件(我的意思是我点击每个复选框)然后我点击菜单,在我的菜单中我删除了我单击它删除所有选中的元素(文件)。对于我的列表视图,我制作了一个适配器:

public class listFiles extends BaseAdapter {

    private Activity activity;
    private List<FileModelListView> data;
    private static LayoutInflater   inflater = null;
    public         ImageView        imageView; 
    public  int    totalChecked    = 0;
    public  String checkedElements = "";



    public MyFilesProfilAdapter(Activity a, List<FileModelListView> files) {
        activity    = a;
        data        = files;
        inflater    = (LayoutInflater)activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        imageView   = new ImageView(activity.getApplicationContext());
    }



    public View getView(int position, View convertView, ViewGroup parent) {

            CheckBox allCheck              = (CheckBox) convertView.findViewById(R.id.cbBox);
            TextView file_title            = (TextView) convertView.findViewById(R.id.title);


            allCheck.setOnCheckedChangeListener( new OnCheckedChangeListener() {
                @Override
                public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                    totalChecked    += 1;
                    // checkedElements += checkedElementValue;

                }
            });



        return convertView;
    }



    @Override
    public int getCount() {
        return data.size();
    }

    @Override
    public Object getItem(int position) {
        return position;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    public int getTotalChecked() {
        return totalChecked;
    }

    public String getCheckedElements() {
        return checkedElements;
    }
}

现在我在checkedElements中保存了evry checked元素后,我希望在我的函数中得到它们:

public boolean onOptionsItemSelected (MenuItem item) {

        switch (item.getItemId()) {
          case R.id.delete:
             // getckeckedElements How?
          break;
       }
       return true;
    }

0 个答案:

没有答案