I have three different activities sharing exactly the same layout (a ListView and a TextView). The ListView uses this layout for its SimpleCursorAdapter:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:paddingBottom="2dp"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="@+id/locationName"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="left"
android:text="Länsnamn"
android:textAppearance="?android:attr/textAppearanceMedium">
</TextView>
<LinearLayout
android:id="@+id/num_stores_row"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="@+id/numStores_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="left"
android:textSize="10dp"
android:text="Antal butiker: ">
</TextView>
<TextView
android:id="@+id/numStores"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="10dp"
android:text="0">
</TextView>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="@+id/numItems_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="left"
android:textSize="10dp"
android:text="Antal artiklar: ">
</TextView>
<TextView
android:id="@+id/numItems"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="10dp"
android:text="0">
</TextView>
</LinearLayout>
</LinearLayout>
The program goes from activity #1, user picks an item in the list, activity #2 starts, user picks list, activity #3 starts.
Now, all the list items turn up fine just like they should, but for activity #3 I’d like to remove the entire row with id num_stores_row, and I seem to have a hard time doing this. I cannot do this in the setViewBinder since the row is not targeted by the adapter, and I cannot do it outside since the ListView is not activated until the data arrives. I’ve tried findViewById(R.id.num_stores_row).setVisibility(View.GONE); here and there, but the simulator crashes every time.
How do I remove it?
To add to what Mark said, override SimpleCursorAdapter’s getView and put your findViewById(R.id.num_stores_row).setVisibility(View.GONE); in there once you inflate the row’s view.