Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid ListView causing CheckBoxes and CheckedTextViews to disappear
    primarykey
    data
    text
    <p>I've seen other similar problems to this around, but nothing that quite addresses the issues. My problem is that Checkboxes and CheckedTextViews are randomly disappearing from my list. That is, they are the the first time the ListView is loaded, as well as the first scroll all the way to the bottom. Any random scrolling causes the CheckBoxes to just drop out and disappear. </p> <p>Here is the code for my extended SimpleCursorAdapter.</p> <pre><code>public class CheckBoxCursorAdapter extends SimpleCursorAdapter{ static final String TAG = "CheckBoxCursorAdapter"; final Context contextMain; Cursor c; SQLiteDatabase db; public CheckBoxCursorAdapter(Context context, int layout, Cursor c, String[] from, int[] to, SQLiteDatabase db) { super(context, layout, c, from, to); this.contextMain = context; this.c = c; this.db = db; } @Override public void bindView(View view, Context context, Cursor cursor) { CheckedTextView cb = (CheckedTextView)view.findViewById(R.id.cb); cb.setOnClickListener(null); TextView cbFull = (TextView)view.findViewById(R.id.fullname); TextView cbAbbrev = (TextView)view.findViewById(R.id.abbrev); cb.setCheckMarkDrawable(android.R.drawable.btn_default); final String abbrv = cursor.getString(cursor.getColumnIndexOrThrow(BuildingOpenHelper.C_ABBRV)); cbFull.setText(cursor.getString(cursor.getColumnIndexOrThrow(BuildingOpenHelper.C_NAME))); cbAbbrev.setText(abbrv); cb.setChecked(cursor.getInt(cursor.getColumnIndexOrThrow(BuildingOpenHelper.C_DISPLAYED)) == 1 ? true : false); Log.v(TAG, "displayed = " + Long.toString(cursor.getInt(cursor.getColumnIndexOrThrow(BuildingOpenHelper.C_DISPLAYED)))); cb.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { if(((CheckedTextView) v).isChecked()) { Log.v(TAG, "Calling isChecked==true!"); db.execSQL("UPDATE buildinglist SET displayed='1' WHERE abbrv='"+ abbrv +"'"); ((CheckedTextView) v).setChecked(true); } else { Log.v(TAG, "Calling isChecked==false!"); db.execSQL("UPDATE buildinglist SET displayed='0' WHERE abbrv='"+ abbrv +"'"); //(CheckedTextView) v).setChecked(false); ((CheckedTextView) v).setChecked(false); } } }); final int latitude = cursor.getInt(cursor.getColumnIndexOrThrow(BuildingOpenHelper.C_YCOORD)); final int longitude = cursor.getInt(cursor.getColumnIndexOrThrow(BuildingOpenHelper.C_XCOORD)); view.setOnLongClickListener(new OnLongClickListener() { @Override public boolean onLongClick(View v) { // Log.v(TAG, "Calling isChecked==true!"); // db.execSQL("UPDATE buildinglist SET displayed='1' WHERE abbrv='"+ abbrv +"'"); // ((CheckedTextView) v).setChecked(true); Intent i = new Intent(contextMain,View_map.class); i.putExtra("lat", latitude); i.putExtra("long", longitude); Log.d(TAG,"Latitude onLongClick" + latitude + ""); Log.d(TAG,"Longitude onLongClick" + longitude +""); contextMain.startActivity(i); return false; } }); } } </code></pre> <p>I am using a ListActivity, here is the initiation.</p> <pre><code>public class Buildings_List extends ListActivity{ BuildingOpenHelper opener; SQLiteDatabase db; SQLiteDatabase dbWrite; static final String[] FROM = {BuildingOpenHelper.C_NAME, BuildingOpenHelper.C_ABBRV, BuildingOpenHelper.C_DISPLAYED}; static final int[] TO = { R.id.fullname, R.id.abbrev, R.id.cb }; private static final String TAG = "Buildings_List"; SimpleCursorAdapter adapt; Cursor myCur = null; Bundle savedInstanceState2; @Override public void onCreate(Bundle savedInstanceState) { savedInstanceState2 = savedInstanceState; super.onCreate(savedInstanceState2); ListView awesome = getListView(); opener = new BuildingOpenHelper(this); db = opener.getReadableDatabase(); dbWrite = opener.getWritableDatabase(); try { myCur = db.query(BuildingOpenHelper.TABLE,null,null,null,null,null,BuildingOpenHelper._ID + " DESC"); } catch(SQLException e){ Log.d(TAG,"Query Went Bad"); } startManagingCursor(myCur); //using depracated SimpleCursorAdapter. Not quite sure what the flags need to be when using updated constructor adapt = new CheckBoxCursorAdapter(this, R.layout.buildinglisting, myCur, FROM, TO, dbWrite); setListAdapter(adapt); } </code></pre> <p>I know it's not the onClickListeners that are the problem, as I have tried removing those and the problem still persists. I have read multiple accounts of the CheckBoxes not recycling correctly, but the problem is still there with CheckTextViews as well. Is there something really simple that I have missed?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload