Note that there are some explanatory texts on larger screens.

plurals
  1. POUpdating list elements on Spinner list item selection - Android
    primarykey
    data
    text
    <p>A little context: I have a stable tutorials app on the market. Recently the users have been requesting some external sources where they can learn more. This question is regarding the solution I came up with.</p> <p>I have an activity with a listview and a spinner on top.</p> <p>The listview can be populated with up to 25 elements at once (should I make it lesser?) .... I want the spinner to have options like (1-25, 26-50, 51-75).</p> <p>The default can be set to 1-25. Depending on what the user selects, I need to re-populate the listview accordingly. I reckon a two dimensional array would be the neatest. But I don't want to hinder the performance too.</p> <p>Anyways, here's what I've done yet. I need to know how exactly should I update the listview elements in the Spinners OnClick. </p> <pre><code> Spinner spinner; String path[] = {"Laptops","DesktopPC","Tablets","Add-Ons","Gaming"}; String Laptops[] = {"Dell","Hp","Apple"}; ListView lstView; lstView = (ListView) findViewById(R.id.listView1); ArrayAdapter&lt;String&gt; adapter = new ArrayAdapter&lt;String&gt; (Category.this, android.R.layout.simple_spinner_item, path ); spinner = (Spinner) findViewById(R.id.spinner1); spinner.setAdapter(adapter); spinner.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView&lt;?&gt; arg0, View arg1, int arg2, long arg3) { // TODO Auto-generated method stub ArrayAdapter&lt;String&gt; lstAdapter = new ArrayAdapter&lt;String&gt;(getApplicationContext(), android.R.layout.simple_list_item_1, Laptops); lstView.setAdapter(lstAdapter); //lstView.refreshDrawableState(); } }); </code></pre> <p>Assume that I have to switch between the two arrays depending on the spinner selection.</p> <p>Thank you for reading! If you require any more information, kindly ask :-)</p>
    singulars
    1. This table or related slice is empty.
    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