tags:

views:

111

answers:

1

Hi,

Ive got ListActivity and i am using custom CursorAdapter.

in each item of the list ive got also checkbox...

now i have in my list screen a perm button, when you press on it,

it should find all the checkboxes which are 'checked' and do some operations on the item which it's checkbox is 'checked'.

how can i retrive all the checked ones?

ive done focusable:false, so i can use OnClickListener, but i dont know how farther then this.. Thanks,

some code:

this is in my ListActivity class:

    final String columns[] = new String[] { MyUsers.User._ID,
            MyUsers.User.MSG, MyUsers.User.LOCATION };

    int[] to = new int[] { R.id.toptext,   R.id.bottomtext,R.id.ChkBox,

R.id.Location};

    Uri myUri = Uri
    .parse("content://com.idan.datastorageprovider/users");

    Cursor cursor = getContentResolver().query(myUri, columns, null, null, null);  

                startManagingCursor(cursor);  


    ListCursorAdapter myCursorAdapter=new ListCursorAdapter(this,
            R.layout.listitem, cursor, columns, to);

     this.setListAdapter(myCursorAdapter);

and this is my Custom Cursor adapter class:

public class ListCursorAdapter extends SimpleCursorAdapter

{

     private Context context;
private int layout;

public ListCursorAdapter(Context context, int layout, Cursor c,
        String[] from, int[] to)
{
    super(context, layout, c, from, to);

    this.context = context;

    this.layout = layout;

}

@Override
public View newView(Context context, Cursor cursor, ViewGroup parent)
{

    Cursor c = getCursor();

    final LayoutInflater inflater = LayoutInflater.from(context);
    View v = inflater.inflate(layout, parent, false);
               return v;
      }

@Override

public void bindView(View v, Context context, Cursor c)
{
    TextView topText = (TextView) v.findViewById(R.id.toptext);
    if (topText != null)
    {
        topText.setText("");
    }

    int nameCol = c.getColumnIndex(MyUsers.User.MSG);
    String name = c.getString(nameCol);
    TextView buttomTxt = (TextView) v.findViewById(R.id.bottomtext);
    if (buttomTxt != null)
    {
        buttomTxt.setText("Message: "+name);
    }

    nameCol = c.getColumnIndex(MyUsers.User.LOCATION);
    name = c.getString(nameCol);
    TextView location = (TextView) v.findViewById(R.id.Location);
    if (locationLinkTxt != null)
    {
        locationLinkTxt.setText(name);
    }

    }
A: 
        //Modify to meet your needs
        String[] from = new String[]{ YourDbAdapter.KEY_WORDS_ROWID, YourDbAdapter.KEY_WORDS_ROWID};
        int[] to = new int[]{ R.id.row_item_checkbox};

        mAdapter = new SimpleCursorAdapter(this, R.layout.row_item_with_checkbox, yourDbCursor, from, to);


      mAdapter.setViewBinder(new SimpleCursorAdapter.ViewBinder() {

       @Override
       public boolean setViewValue(View view, Cursor cursor, int columnIndex) {


        if(view.getId() == R.id.myCheckbox )
        { 

         CheckBox cb = (CheckBox) view;
         cb.setOnClickListener(new OnClickListener() {

          @Override
          public void onClick(View v) {

           final long id = cursor.getLong(columnIndex); //Your row id
                               //You can do the necessary work here such as adding to an List or somehting

          }
         });


         return true; 
        } 

        return false;
       }


      });
jax
YOUR_DB_INTEX_HERE=??
rayman
and if u meant, DataBase Index, i am not sure realy what should i put there? how is my checkboxes status is connected to my database?
rayman
if anyone could help out? i am realy stuck here.. cant figure out how i should continue..
rayman
Well you said that you were getting you results from a database. So it May be something like dBConnectionHelper.INDEX_MYTABLE_COLUMN. If you are not connecting the checkbox to any database field then don't worry about that part, just delete it. When you setup you Cursor adapter just link the _id from the database with the checkbox from your layout. That way you can use the _id to perform the SQL operations in your database later.
jax
I changed it to better suit your situation - see above
jax
Thank you, but not sure i understoond, or mybe u didnt.. i am connecting my items to the database, just not the checkbox part which is in the item.okie i will edit my question and put code example of what i have
rayman