Note that there are some explanatory texts on larger screens.

plurals
  1. POSwitch cases maximum implementation?
    primarykey
    data
    text
    <p>I am using a single switch cases which will have more than 100 cases statement to be used. Are there any limit ?</p> <p>The usage of cases are for the suggestions of my AutoCompleteTextView, android tutorial.</p> <p>Here are part of my codes, ignore the Badrul.class they will be changed later.</p> <pre><code>import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.view.View; import android.widget.AdapterView; import android.widget.AdapterView.OnItemClickListener; import android.widget.ArrayAdapter; import android.widget.AutoCompleteTextView; import android.widget.Toast; public class Search extends Activity { public void onCreate(Bundle savedInstanceSate) { final AutoCompleteTextView autoComplete; super.onCreate(savedInstanceSate); setContentView(R.layout.searchshop); autoComplete = (AutoCompleteTextView) findViewById(R.id.autoCompleteTextView1); ArrayAdapter&lt;String&gt; adapter = new ArrayAdapter&lt;String&gt;(this, R.layout.list_item, shops); autoComplete.setAdapter(adapter); autoComplete.setThreshold(1); autoComplete.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView&lt;?&gt; arg0, View arg1, int position, long arg3) { int index=999; for(int i=0;i&lt;shops.length;i++) { if(autoComplete.getText().toString().trim().equals(shops[i])) { index=i; break; } } switch(index) { case 0: startActivity(new Intent(Search.this, Adidas.class)); break; case 1: startActivity(new Intent(Search.this, Affin.class)); break; case 2: startActivity(new Intent(Search.this, AlamArt.class)); break; case 3: startActivity(new Intent(Search.this, AlAmin.class)); break; case 4: startActivity(new Intent(Search.this, Anakku.class)); break; case 5: startActivity(new Intent(Search.this, Anggerik.class)); break; case 6: startActivity(new Intent(Search.this, Asiari.class)); break; case 7: startActivity(new Intent(Search.this, AsterSpring.class)); break; case 8: startActivity(new Intent(Search.this, Audrey.class)); break; case 9: startActivity(new Intent(Search.this, Badrul.class)); break; case 10: startActivity(new Intent(Search.this, Badrul.class)); break; case 11: startActivity(new Intent(Search.this, Badrul.class)); break; default: Toast.makeText(Search.this, "Invalid Selection", Toast.LENGTH_SHORT).show(); } } }); } static final String[] shops = new String[] { "Adidas", "Affin Bank ATM", "Alam Art Gallery", "Al Amin Kids", "Anakku", "Anggerik", "Asiari", "Aster Spring", "Audrey", "Badrul Songket", "Bata"}; } </code></pre>
    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.
 

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