I have a ListView that reads data from sqlite with SimpleCursorAdapter and the table has about 1000 rows but i've filtered my list in my Activity by date, so the filtered cursor contains 2 rows for that special day.Therefor i wanted to add a custom row number(can't use _id) for my list.one soloution that i've tought about,was ViewBinder, here is my code:
adapter.setViewBinder(new ViewBinder() {
public boolean setViewValue(View aView, Cursor aCursor, int aColumnIndex) {
if (aColumnIndex == 0) {
aCursor.moveToFirst();
if(aCursor.moveToFirst()) {
TextView textView = (TextView) aView;
textView.setText("" + WeeklyListRowNumber);
WeeklyListRowNumber = WeeklyListRowNumber + 1;
}
return true;
}
return false;
}
});
I have 11 columns in my List and WeeklyListRowNumber initialized 1 on the top,my problem is my rownumbers turns to 7,8 but it must be 1 , 2.can somebody tells me how can I solve this issue?
public View getView(int position, View convertView, ViewGroup parent) {
View retval = null;
retval = LayoutInflater.from(parent.getContext()).inflate(
R.layout.content, null);
title = (TextView) retval.findViewById(R.id.contactName);
number = (TextView) retval.findViewById(R.id.contactNumber);
title.setText(text to display in list);
number.setText(""+position);//add row number to list //fixed the variable
}
As You are using the adapter for the list view so u may getting the position variable in getview .
Use that position (int) as custom list row number
it will start from zero(0).
Set it according as per requirement...
finaly i've soved my problem with ViewBinder :
adapter.setViewBinder(new SimpleCursorAdapter.ViewBinder() {
public boolean setViewValue(View aView, Cursor aCursor, int aColumnIndex) {
if (aColumnIndex == 0) {
TextView textView = (TextView) aView;
int CursorPos = aCursor.getPosition() + 1;
textView.setText(Integer.toString(CursorPos));
return true;
}
return false;
}});
Related
I have a SimpleCursorAdapter class, it gets various data from DB and displays in ListView. It implements an onclicklistener that sends a messageGuid String to another activity. All this works fine.
In the row of the ListView i have added a CheckBox and set an onCheckChangeListener to it. At the moment when the checkbox is checked, the messageGuid is always the last one in the cursor.
I need to find a way to get the listview row id of the row which hold the checkbox that has been checked. I can then get the correct cursor row and then in turn the correct messageGuid.
I've commented what i would like within the onCheckedChanged method.
Thanks in advance Matt.
private class MyAdapter extends SimpleCursorAdapter implements OnItemClickListener {
Cursor c;
String messageGuid;
public MyAdapter(Context context, int layout, Cursor c, String[] from,
int[] to) {
super(context, layout, c, from, to);
}
#Override
public
View getView(int position, View convertView, ViewGroup parent) {
Log.e(TAG, "inside myadapter getview for messages");
View v = super.getView(position, convertView, parent);
if(v == null)
return null;
c = (Cursor)getItem(position);
Log.e(TAG, "(Cursor)getItem(position) = " + c + "position = " + position);
v.setTag(c);
//other code removed, not relevant
String messageSender = c.getString(c.getColumnIndex(LoginValidate.C_MESSAGE_SENDER));
String isRepliedTo = c.getString(c.getColumnIndex(LoginValidate.C_MESSAGE_REPLIED));
String isStandAlone = c.getString(c.getColumnIndex(LoginValidate.C_MESSAGE_IS_STANDALONE));
((TextView)v.findViewById(R.id.messagecreatedat)).setText(formattedMessCreatedAt );
((TextView)v.findViewById(R.id.messagetext)).setText(messageText);
((TextView)v.findViewById(R.id.messagesender)).setText(messageSender);
//#003F87 = blue
((TextView)v.findViewById(R.id.messagecreatedat)).setTextColor(Color.parseColor("#003F87"));
((TextView)v.findViewById(R.id.messagesender)).setTextColor(Color.parseColor("#003F87"));
((TextView)v.findViewById(R.id.messagetext)).setTextColor(Color.parseColor("#FF0000"));
CheckBox cb = ((CheckBox)v.findViewById(R.id.list_checkbox));
cb.setOnCheckedChangeListener(new OnCheckedChangeListener() {
#Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
//i'd like to something like below where i can specify the row which contains
//the checkbox that has been check and map that to the row in the cursor.
// So if the checkbox in the 2nd row in the listview has been clicked then the messageGuid from the 2nd row in the cursor is found
//c.moveToPosition(the row position of the listview which holds the checkbox that has been clicked );
messageGuid = null;
messageGuid = c.getString(c.getColumnIndex(LoginValidate.C_MESSAGE_GUID));
if(isChecked == true){
Log.e(TAG, "checkBox true and guid = " + messageGuid);
}else{
Log.e(TAG, "checkBox false and guid = " + messageGuid);
}
}
});
return v;
}
#Override
public void onItemClick(AdapterView<?> parent, View view, int pos,
long id) {
Cursor itemCursor = (Cursor) view.getTag();
String messageGuid = itemCursor.getString(itemCursor.getColumnIndex(LoginValidate.C_MESSAGE_GUID));
String messageText = itemCursor.getString(itemCursor.getColumnIndex(LoginValidate.C_MESSAGE_TEXT));
String messageCreatedAt = itemCursor.getString(itemCursor.getColumnIndex(LoginValidate.C_MESSAGE_CREATED_AT));
String messageSender = itemCursor.getString(itemCursor.getColumnIndex(LoginValidate.C_MESSAGE_SENDER));
String messageReplied = itemCursor.getString(itemCursor.getColumnIndex(LoginValidate.C_MESSAGE_REPLIED));
String messageSeen = itemCursor.getString(itemCursor.getColumnIndex(LoginValidate.C_MESSAGE_SEEN));
String isStandAlone = itemCursor.getString(itemCursor.getColumnIndex(LoginValidate.C_MESSAGE_IS_STANDALONE));
Intent i = new Intent(ViewMessagesActivity.this, ReplyToMessageActivity.class);
i.putExtra("guid", messageGuid);
i.putExtra("message", messageText);
i.putExtra("createdat", messageCreatedAt);
i.putExtra("sender", messageSender);
i.putExtra("messagereplied", messageReplied);
i.putExtra("messageseen", messageSeen);
i.putExtra("isstandalone", isStandAlone);
startActivity(i);
}
}// end of adapter
Make position final and use that on onCheckedChanged
or
make cb final
Add before cb.setOnCheckedChangeListener
cb.setTag(position);
And in public void onCheckedChanged you can retrieve the position
int pos = (Integer) cb.getTag();
I'm using multiple selection on the listview in my app which is being populated by db (SimpleCursorAdapter). There's some weird behavior with the listview selection.
If there are more than 7 items in the database, if I select the 1st item in the listview, the 8th item also gets selected even when I'm not selecting the 8th item and vice-versa. If I select the 9th item, the 2nd row gets selected.
What's happening here?
Code:
String[] projection = { ..table_columns..};
String[] from = { table_columns..};
Cursor cursor = contentResolver.query(SomeContentProvider.CONTENT_URI, projection, null, null,
null);
// the XML defined views which the data will be bound to
int[] to = new int[] {
R.id.color,
R.id.name,
R.id.desc,
};
// create the adapter using the cursor pointing to the desired data
//as well as the layout information
dataAdapter = new SimpleCursorAdapter(
this, R.layout.layout_main,
cursor,
from,
to,
0);
dataAdapter.setViewBinder(new SimpleCursorAdapter.ViewBinder() {
#Override
public boolean setViewValue(View view, Cursor cursor, int column) {
int nNameIndex = cursor.getColumnIndexOrThrow(EventsTable.COLUMN_NAME);
if( column == nNameIndex ){
TextView nname = (TextView) view;
String name = cursor.getString(cursor.getColumnIndex(EventsTable.COLUMN_NAME));
String formatted_name = "NAME: " +name;
nname.setText(formatted_name);
return true;
}
return false;
}
});
listView.setAdapter(dataAdapter);
listView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
listView.setOnItemLongClickListener(new OnItemLongClickListener() {
#Override
public boolean onItemLongClick(AdapterView<?> av, View v, int pos, long id) {
if (!listView.isItemChecked(pos)){
listView.setItemChecked(pos, true);
v.setBackground(getResources().getDrawable(R.drawable.listview_bg_selected));
v.setSelected(true);
} else {
listView.setItemChecked(pos, false);
v.setBackground(getResources().getDrawable(R.drawable.listview_bg));
v.setSelected(false);
}
if (listView.getCheckedItemCount() > 0) {
if (mMode == null) {
mMode = startActionMode(new ActionModeCallback());
} else {
mMode.setTitle(listView.getCheckedItemCount() + " " + "Selected");
}
} else {
if (mMode != null) {
mMode.finish();
}
}
return true;
}
});
I suspect it's because in your bindView of your adapter you are not checking if the item is checked, and then changing the background appropriately.
You experiencing your views being recycled.
So when you scroll, and say item one goes out of view and was selected, the view for item 1 is reused for item 8.
SO add something like this to your view binder
int post = cursor.getPosition();
if (!listView.isItemChecked(pos)){
v.setBackground(getResources().getDrawable(R.drawable.listview_bg_selected));
} else {
v.setBackground(getResources().getDrawable(R.drawable.listview_bg));
}
I put a list of exercises in the lesson. The user can modify this exercise to show or not. When he clicks on the exercise, changing the status (show or not show) exercise.
All changes made to the database works fine. But when the user made the change, when you scroll through the picture "check" is displayed not correctly in emerging lines.
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
....
db = new MyDatabase(this);
getOnListExes();
db.close();
}
....
public void getOnListExes() {
onListExesChek = db.getListExes(prog_man, prog_woman, orderBy);
sAdapter = new SimpleCursorAdapter(this,
R.layout.exeslist, onListExesChek,
new String[] {"exes_bodypart", "exes_name", "exes_name"},
new int[] {R.id.exesPartlist_chek, R.id.exesNamelist_chek,
R.id.chek_img}) {
public View getView(int position, View convertView, ViewGroup parent) {
View row = super.getView(position, convertView, parent);
TextView exesPartlist_chek =
(TextView) row.findViewById(R.id.exesPartlist_chek);
TextView exesNamelist_chek =
(TextView) row.findViewById(R.id.exesNamelist_chek);
ImageView imageGender =
(ImageView) row.findViewById(R.id.chek_img);
return row;
}
};
sAdapter.setViewBinder(new MyViewBinder());
listExesChek.setAdapter(sAdapter);
}
public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
positionChek = position;
selectExe_id = Long.toString(id);
db = new MyDatabase(this);
onListExesChek = db.getListExes(prog_man, prog_woman, orderBy);
onListExesChek.moveToPosition(positionChek);
if (
onListExesChek.getInt(onListExesChek.getColumnIndex("prog_man_chek"))
>= Integer.valueOf(prog_man).intValue() &
onListExesChek.getInt(onListExesChek.getColumnIndex("prog_woman_chek"))
>= Integer.valueOf(prog_woman).intValue()) {
if(prog_man.equals("1")) {
prog_man_chek = new ContentValues();
prog_man_chek.put("prog_man_chek", "0");
int upProg_man_chek = db.setExe(prog_man_chek,
selectExe_id);
}
if(prog_woman.equals("1")) {
prog_woman_chek = new ContentValues();
prog_woman_chek.put("prog_woman_chek", "0");
int upProg_woman_chek = db.setExe(prog_woman_chek,
selectExe_id);
} else {
if(prog_man.equals("1")) {
prog_man_chek = new ContentValues();
prog_man_chek.put("prog_man_chek", "1");
int upProg_man_chek = db.setExe(prog_man_chek,
selectExe_id);
}
if(prog_woman.equals("1")) {
prog_woman_chek = new ContentValues();
prog_woman_chek.put("prog_woman_chek", "1");
int upProg_woman_chek = db.setExe(prog_woman_chek,
selectExe_id);
}
}
db.close();
updateView(position);
}
void updateView(int index){
db = new MyDatabase(this);
onListExesChek = db.getListExes(prog_man, prog_woman, orderBy);
onListExesChek.moveToPosition(positionChek);
View v = listExesChek.getChildAt(index -
listExesChek.getFirstVisiblePosition());
if (
onListExesChek.getInt(onListExesChek.getColumnIndex("prog_man_chek"))
>= Integer.valueOf(prog_man).intValue() &
onListExesChek.getInt(onListExesChek.getColumnIndex("prog_woman_chek"))
>= Integer.valueOf(prog_woman).intValue()
) {
ImageView imageGender = (ImageView) v.findViewById(R.id.chek_img);
imageGender.setImageResource(R.drawable.check);
} else {
ImageView imageGender = (ImageView) v.findViewById(R.id.chek_img);
imageGender.setImageResource(R.drawable.notchek);
}
db.close();
}
class MyViewBinder implements SimpleCursorAdapter.ViewBinder {
public boolean setViewValue (View view, Cursor cursor, int columnIndex) {
switch (view.getId()) {
case R.id.chek_img:
if (onListExesChek.getInt(onListExesChek.
getColumnIndex("prog_man_chek"))
>= Integer.valueOf(prog_man).intValue() &
onListExesChek.getInt(onListExesChek.getColumnIndex("prog_woman_chek"))
>= Integer.valueOf(prog_woman).intValue()
) {
((ImageView) view).setImageResource(R.drawable.check);
} else {
(
(ImageView) view).setImageResource(R.drawable.notchek);
}
return true;
}
return false;
}
}
It's a side-effect of ListView's view recycling. You're not setting a default resource in the getView method so the ImageView will "keep" whatever you set it to in the updateView method. This effect is really noticeable in longer lists where you'll see a repeating incorrect state.
You should be able to fix this by setting the state of the ImageView within your getView method.
ListViews recycle views, which means at first a base set of list entries is inflated from XML.
for more check
android listview displays false data after scrolling (custom adapter)
ListView is not showing correct values after scrolling
both works for me
I did a query in a database and return it inside a list that i put on a custom adapter and then i put in a listview.
Works fine until i use the onItemClikListener. I want to get the column "_id" from the query and i don't know how to do it (i want to pass this id as parameter for another activity).
I tried getItemId from my custom adapter but it returns the position on the list, not the column "_id".
Ex.: my query select * where name = x; return rows with id 1 and 3...but the getItemId make it position 1="_id1" and 2="_id3"...and when i pass it no another activity the query returns the rows with the "_id" 1 and 2;
//Here i get the item position and pass to another activity
listagem.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> arg0, View arg1,int position, long id) {
String Column_id = String.valueOf(adapter.getItemId(position));
Intent mostraLetra = new Intent(musica.this.getActivity(), ExibeMusica.class);
mostraLetra.putExtra("id", Column_id);
startActivity(mostraLetra);
}
});
//Here i pass the Id when i click on a item on the list
public String[] exibeMusica(String idMusica){
String r = idMusica;
String[] resultado = {};
Cursor resul = bancodados.query(Tabela_musica, new String[] {"_id", "Musica","Cantor","letra_musica","cat_oracao","cat_missa"}, "_Id = " +r+"", null, null, null, null, null);
resul.moveToFirst();
resultado[0] = String.valueOf(resul.getString(resul.getColumnIndex("_id")));
resultado[1] = resul.getString(resul.getColumnIndex("Musica"));
resultado[2] = resul.getString(resul.getColumnIndex("Cantor"));
resultado[3] = resul.getString(resul.getColumnIndex("letra_musica"));
resultado[4] = resul.getString(resul.getColumnIndex("cat_oracao"));
resultado[5] = resul.getString(resul.getColumnIndex("cat_missa"));
resul.close();
return resultado;
}
//This is my custom adapter
public class CustomAdapter extends BaseAdapter{
LayoutInflater inflater;
List<musica.ItemLista> itens;
public CustomAdapter(Activity a, List<musica.ItemLista> itens) {
super();
this.itens = itens;
this.inflater = (LayoutInflater)a.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
public int getCount() {
// TODO Auto-generated method stub
return itens.size();
}
public Object getItem(int position) {
return position;
}
public long getItemId(int position) {
return position;
}
public View getView(int position, View convertView, ViewGroup parent) {
musica.ItemLista item = itens.get(position);
View vi = convertView;
if(convertView==null){
vi = inflater.inflate(R.layout.linha_listview, null);
TextView id = (TextView)vi.findViewById(R.linhaLista.id);
TextView musica = (TextView)vi.findViewById(R.linhaLista.musica);
TextView artista = (TextView)vi.findViewById(R.linhaLista.cantor);
ImageView oracao = (ImageView)vi.findViewById(R.linhaLista.cat_oracao);
ImageView missa = (ImageView)vi.findViewById(R.linhaLista.cat_missa);
id.setText(String.valueOf(item.id));
musica.setText(item.musica);
artista.setText(item.cantor);
String imgOra = item.oracao;
String imgMissa = item.missa;
if (imgOra.equals(null)) {
oracao.setImageResource(R.drawable.blank);
}else if(imgOra.equals("louvor")) {
oracao.setImageResource(R.drawable.louvor);
}else if(imgOra.equals("adoracao")) {
oracao.setImageResource(R.drawable.adoracao);
}
if (imgMissa.equals(null)) {
missa.setImageResource(R.drawable.blank);
}else if(imgOra.equals("louvor")) {
missa.setImageResource(R.drawable.louvor);
}else if(imgOra.equals("adoracao")) {
missa.setImageResource(R.drawable.adoracao);
}
}return vi;
}
}
Anyone can help me to get the correct "_id" ?
Set tag to the row view in getView of the adapter like this
.........
}
vi.setTag(String.valueOf(item.id))
return vi;
.........
and then
public void onItemClick(AdapterView<?> arg0, View arg1,int position, long id) {
String Column_id = (String) arg1.getTag();
......
While setting the linha_listview.xml in your CustomAdapter, you try to add one more textview to the linha_listview.xml like below:
<TextView
android:id="#+id/pid"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:visibility="gone" />
As you set this visibility to gone, it is no more visible on the listview. Later you set this textview by pidtextview.setText(column_id) in your getView() method. So, while clicking on the list item, get this column_id by
String pid = ((TextView) view.findViewById(R.id.pid)).getText().toString();
in your list item listener. By this above code, you would get the pid, Pass this to the other activity through intent.putExtra(); In that activity retrieve the data from getIntent() and retrieve the data of that particular row which contains that column_id and display that particular row details on that activity. Hope this helps. If you still get any doubts, get back.
write this code in onItemClickListner
resul.moveToPosition (position)
String Column_id = resul.getString(resul.getColumnIndex("_id");
I have an issue with Spinners in a ListView. I have a ListView with a CheckBox, a label, and two Spinners. The Spinner are populated from SQLite and that is working fine. I am not using the ViewHolder method because so far when the ListView row is clicked the CheckBoxes are checked or unchecked and the change is immediately saved to the database. When the row is checked the Spinners are made visible but are not visible when the row is not checked.
So the issue that I haven't managed to find a solution for is that I have no idea how to get the actual Spinner or even get the ListItem row that the clicked Spinner is on. The Activity extends ListActivity. Anyone know a way I can do this without using a ViewHolder or do I have to use a ViewHolder?
Here is the code that declares and populates the ListView:
mSsCursor = mDbHelper.fetchAllSsPlaylistSs(mPlId);
startManagingCursor(mSsCursor);
String[] from = new String[]{"pl_selected", BTDbAdapter.KEY_NAME, BTDbAdapter.KEY_NAME2};
int[] to = new int[]{R.id.pl_selected, R.id.name, R.id.name2};
mAllSs = new SimpleCursorAdapter(this, R.layout.pl_edit_ss_row, mSsCursor, from, to);
mAllSs.setViewBinder(new SimpleCursorAdapter.ViewBinder() {
//custom handling of setting the value
public boolean setViewValue(View view, Cursor cursor, int columnIndex) {
if(columnIndex == 3) {
ViewGroup row = (ViewGroup)view.getParent().getParent();
mSId = cursor.getInt(0);
if (cursor.getInt(3) > 0) {
mCheckBox = (CheckBox) row.findViewById(R.id.pl_selected);
mCheckBox.setChecked(true);
mTSpin = (Spinner) row.findViewById(R.id.pl_t_spin);
mMSpin = (Spinner) row.findViewById(R.id.pl_m_spin);
mtvT = (TextView) row.findViewById(R.id.pl_t);
mtvM = (TextView) row.findViewById(R.id.pl_m);
mTSpin.setVisibility(View.VISIBLE);
mtvT.setVisibility(View.VISIBLE);
mMSpin.setVisibility(View.VISIBLE);
mtvM.setVisibility(View.VISIBLE);
//set the values in the t spinner
PopulateTSpinner(cursor.getInt(4));
//set the values in the m spinner
PopulateMSpinner(cursor.getInt(5));
}
else {
mCheckBox = (CheckBox) row.findViewById(R.id.pl_selected);
mCheckBox.setChecked(false);
mTSpin = (Spinner) row.findViewById(R.id.pl_t_spin);
mMSpin = (Spinner) row.findViewById(R.id.pl_m_spin);
mtvT = (TextView) row.findViewById(R.id.pl_t);
mtvM = (TextView) row.findViewById(R.id.pl_m);
mTSpin.setVisibility(View.GONE);
mtvT.setVisibility(View.GONE);
mMSpin.setVisibility(View.GONE);
mtvM.setVisibility(View.GONE);
}
return true;
}
return false;
}
});
setListAdapter(mAllSs);
Thanks.
I don't know if I understood your question: If your app flow is:
show a list of data(CheckBox + TextView(Spinners hidden)) ->
user clicks a row(the Spinners appear for that row with(individual) data) ->
user selects something in those Spinners->
save that selection in the database
then I think you should go with a custom adapter and take care yourself of the row creation + data binding(I don't see how you would set a listener for the Spinners). Below is a small example on how you might do this(although probably not a pretty way of doing it):
public class CustomAdapter extends SimpleCursorAdapter {
private LayoutInflater mInflater;
public CustomAdapter(Context context, int layout, Cursor c,
String[] from, int[] to) {
super(context, layout, c, from, to);
mInflater = LayoutInflater.from(context);
}
#Override
public void bindView(View view, Context context, Cursor cursor) {
ViewHolder holder = (ViewHolder) view.getTag(); // the holder
// pattern
// set the text for the TextView in your row
holder.name
.setText(cursor.getString(cursor.getColumnIndex("name")));
// status of the CheckBox from the database
int status = cursor.getInt(cursor.getColumnIndex("pl_selected"));
// set the CheckBox status
holder.ckb.setChecked((status > 0) ? true : false);
// get the id of this particular row, we'll use this later in the
// Spinner's listeners
long theId = cursor.getLong(cursor.getColumnIndex("_id"));
// see if it is time to show the Spinners
if (status > 0) {
// it is time to show the Spinners. Here you would do stuff
// like: setting up the Spinner's adapters + setting the
// listener
// I used a Spinner with entries set in the xml layout(so my
// selection result is a String)
holder.spin1.setVisibility(View.VISIBLE);
holder.spin2.setVisibility(View.VISIBLE);
// set theId as a tag so you know which Spinner was acted on
holder.spin1.setTag(new Long(theId));
holder.spin1
.setOnItemSelectedListener(new OnItemSelectedListener() {
#Override
public void onItemSelected(AdapterView<?> parent,
View view, int position, long id) {
Long realRowId = (Long) parent.getTag();
// I don't know
ContentValues cv = new ContentValues();
// the column where I saved the spinner selected
// item is called "saved_item"
cv.put("saved_item", (String) parent
.getItemAtPosition(position));
// mDb is my SQLiteDatabase instance
mDb.update("tbl", cv, "_id = ?",
new String[] { String
.valueOf(realRowId) });
// I don't know how you saved the data, the
// above is just an example
}
#Override
public void onNothingSelected(AdapterView<?> parent) {
}
});
// also implement the second Spinner like the first one
} else {
// required to prevent a recycled View from causing damage
holder.spin1.setVisibility(View.GONE);
holder.spin2.setVisibility(View.GONE);
}
}
#Override
public View newView(Context context, Cursor cursor, ViewGroup parent) {
View v = mInflater.inflate(R.layout.adapters_listspinner_row,
parent, false);
ViewHolder holder = new ViewHolder();
holder.spin1 = (Spinner) v.findViewById(R.id.spinner1);
holder.spin1.setFocusable(false);
holder.spin2 = (Spinner) v.findViewById(R.id.spinner2);
holder.spin2.setFocusable(false);
holder.name = (TextView) v.findViewById(R.id.textView1);
holder.ckb = (CheckBox) v.findViewById(R.id.checkBox1);
holder.ckb.setFocusable(false);
v.setTag(holder);
return v;
}
class ViewHolder {
Spinner spin1, spin2;
TextView name;
CheckBox ckb;
}
}
Also, the required onListItemcClick method:
#Override
protected void onListItemClick(ListView l, View v, int position, long id) {
// manage the CheckBox state
CheckBox ckb = (CheckBox) v.findViewById(R.id.checkBox1);
ckb.setChecked(!ckb.isChecked());
ContentValues cv = new ContentValues();
cv.put("pl_selected", ckb.isChecked() ? 1 : 0);
mDb.update("tbl", cv, "_id = ?",
new String[] { String.valueOf(id) });
// requery the database so the changes are seen by the adapter, this is horrible!
Cursor re = mDb.query("tbl", null, null, null, null, null, null);
mAllSs.changeCursor(re);
}
As an advice, maybe you could modify the layout of your app and move the Spinners out of the ListView row.