Note that there are some explanatory texts on larger screens.

plurals
  1. POViewSwitcher as a ListView item - how to call .showNext() on correct ViewSwitcher item?
    primarykey
    data
    text
    <p>I have a ListView with ViewSwitcher items. The goal is to tap a list item to switch between ViewSwitcher views. Tapping works as expected, but scrolling away from a tapped item and then back sometimes changes which item is displaying the second view from the ViewSwitcher.</p> <p>Here is my ListView item layout, the ViewSwitcher is @+id/details:</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;RelativeLayout xmlns:android = "http://schemas.android.com/apk/res/android" android:layout_width = "fill_parent" android:layout_height = "wrap_content" &gt; &lt;ViewSwitcher android:id = "@+id/details" android:layout_width = "fill_parent" android:layout_height = "fill_parent" android:measureAllChildren = "false" &gt; &lt;!-- two views I want to switch between are here --&gt; &lt;/ViewSwitcher&gt; &lt;/RelativeLayout&gt; </code></pre> <p>My Activity that finds @id/details and calls .showNext().</p> <pre><code>public class MyActivity extends ListActivity { private MySQLiteOpenHelper data; private SimpleCursorAdapter adapter; private Cursor cursor; public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); String[] FROM = { "_id", "_id", "name", "name" }; int[] TO = { R.id.my_list_id, R.id.my_list_id2, R.id.my_list_name, R.id.my_list_name_details }; data = new MySQLiteOpenHelper(this); cursor = data.myList(); startManagingCursor(cursor); adapter = new SimpleCursorAdapter(this, R.layout.list_item, cursor, FROM, TO); setListAdapter(adapter); ListView list = getListView(); list.setOnItemClickListener(new OnItemClickListener() { public void onItemClick(AdapterView&lt;?&gt; adapter, View view, int position, long id) { ViewSwitcher item = (ViewSwitcher) view.findViewById(R.id.details); item.showNext(); } }); } } </code></pre> <p>I <em>think</em> my problem might be that @id/details is not actually unique, so undefined behavior happens when scrolling.</p> <p>If this is the case, then how can I assign a unique ID to each ViewSwitcher or find the correct ViewSwitcher to call .showNext() on?</p>
    singulars
    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.
    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