Remove selected item from ListView

I want to remove the selected item from ListView

, but I cannot. I've tried many methods, but they don't work for me.

This is a list of my adapters - items come from SD card.

ArrayAdapter<String> adapter = new ArrayAdapter<String>(
                        FindFilesByType.this, android.R.layout.test_list_item,
                        Ringtones); 

      

How to solve this problem?

+2


source to share


3 answers


You can remove an item from the main list and signal the adapter that changed the dataset.



See this method for an example.

+3


source


Inject onitemclickListener and get the item (get id) by clicking on the array, then call arrayList.remove ([ID]); adapter.notifyDataSetChanged ();



+2


source


@Override
            public View getView(final int position, View convertView, ViewGroup parent) {
                // TODO Auto-generated method stub
                LayoutInflater inflater=cntx.getLayoutInflater();
                View row=inflater.inflate(R.layout.bookmark_row,null);

                TextView tv=(TextView)row.findViewById(R.id.txtToc);
                final TextView tv2=(TextView)row.findViewById(R.id.txtPgNo);
                mCursor.moveToPosition(position);
                System.out.println("Count Cursor"+mCursor.getCount());
                if(mCursor.getCount()<=0)
                {
                    tv.setText("No Bookmark Found");
                }
                else
                {
                tv.setText(mCursor.getString(1).toString());
                tv2.setTag(mCursor.getString(0).toString());
                tv2.setOnClickListener(new View.OnClickListener() {

                    @Override
                    public void onClick(View v) {
                        // TODO Auto-generated method stub
                        System.out.println(position);
                        db_conn.onDelete("tab_book", mCursor.getColumnName(0),Integer.parseInt((String) tv2.getTag()));
//                      Toast.makeText(ctx,"Bookmark Deleted", Toast.LENGTH_SHORT).show();
                        mToastTextView=new toastTextview(0, 0, ctx,listAct);
                        mToastTextView.showMessage("Bookmark Deleted");
                        refresh();
                    }
                });
                row.setTag(mCursor.getString(2).toString());
                }
                return row;
            }


        public void refresh()
        {
            mCursor=db_conn.onQueryGetCursor("tab_book",mItems,null, null, null, null, null);
            mCursor.moveToPosition(0);
            notifyDataSetChanged();
            if(mCursor.getCount()<=0)
            {
//              Toast.makeText(ctx, "No Bookmark", Toast.LENGTH_SHORT).show();
                try {
                    mFlingAct.dialogBookmark.dismiss();
                } catch (Exception e) {
                    // TODO: handle exception3
                    e.printStackTrace();
                }

            }

       }

      

+1


source







All Articles