samedi 16 décembre 2017

how to delete files of listview from menuInflater

I'm creating an app in which i can search for files and delete it from sdcard.everything is working fine but i can't able to delete files which is checked in listview.

enter code here
@Override
public View getView(final int position, View convertView, ViewGroup parent)
{
    // TODO Auto-generated method stub
    LayoutInflater inflater = ((Activity)context).getLayoutInflater();
    convertView = inflater.inflate(R.layout.row, parent, false); 

    viewholder = new ViewHolder();

    viewholder.checkbox = (CheckBox) convertView.findViewById(R.id.checkBox1);
    viewholder.texview = (TextView) convertView.findViewById(R.id.textView1);

    viewholder.texview.setText(modelItems.get(position));

    viewholder.checkbox.setChecked(checkBoxState[position]);



    viewholder.checkbox.setOnClickListener(new View.OnClickListener(){

            @Override
            public void onClick(View p1)
            {
                // TODO: Implement this method
                if (((CheckBox) p1).isChecked())
                {
                    checkBoxState[position] = true;
                    filepath = modelItems.get(position);
                }
                else
                {
                    checkBoxState[position] = false;
                }
            }
        });
    return convertView;
}

How can i delete files which is selected in listview and also make change in listview?

enter code here
@Override
public boolean onMenuItemSelected(int featureId, MenuItem item)
{
    // TODO: Implement this method
    switch (item.getItemId())
    {
        case R.id.select_all:
            adapter.selectAll();
            return true;

        case R.id.deselect:
            adapter.unSelectAll();
            return true;

        case R.id.delete:
            adapter.delete();
            return true;
    }
    return super.onMenuItemSelected(featureId, item);
}




Aucun commentaire:

Enregistrer un commentaire