title: How to do switch case statement to display ListView in Android
body: <p>I newbie in this field.
  my application have 6 buttons with different category. when i click on one of the button it will go to another page for displaying listView for particular category in my database.</p>
  
  <p>my problem is, I don't know how do switch case for this method.</p>
  
  <pre><code>Log.d("Reading", "Reading all Kategori ..");
       List&lt;UkmLocation&gt; kategori = db.getCategoryFaculty();
  
       for(UkmLocation k : kategori) {
         results.add(k.getName());
         results_id.add(k.getID());
          }
  
            adapter = new ArrayAdapter&lt;String&gt;(this, R.layout.list_item,     R.id.textView1,results);     
              setListAdapter(adapter);
  </code></pre>
  
  <p>I want to include getCategoryHall, getCategoryFacilty,and getCategoryAdmin in this QSFacultyLocation.java. so that, i no need to create another activity merely to get getCategoryHall, getCategoryFacilty,and getCategoryAdmin (listView).Because it just using same coding.</p>
  
  <p>below is my full code for:</p>
  
  <p>QSFacultyLocation.java</p>
  
  <pre><code>package com.example.ukmlocationsearching;
  
  import java.util.ArrayList;
  import java.util.List;
  
  import com.example.ukmlocationsearching.R;
  
  import android.os.Bundle;
  import android.app.Activity;
  import android.app.ListActivity;
  import android.content.Intent;
  import android.text.Editable;
  import android.text.TextWatcher;
  import android.util.Log;
  import android.view.Menu;
  import android.view.View;
  import android.widget.AdapterView;
  import android.widget.ArrayAdapter;
  import android.widget.EditText;
  import android.widget.ListView;
  import android.widget.TextView;
  import android.widget.Toast;
  import android.widget.AdapterView.OnItemClickListener;
  
  public class QSFacultyLocation extends ListActivity {
  
      //------------------------------------------------------------------
          // Declaration
          public static UkmLocation selectedPOI = null;
          final DatabaseHandler db = new DatabaseHandler(this);
          private EditText filterText = null;
          ArrayAdapter&lt;String&gt; adapter = null;
          final ArrayList&lt;String&gt; results = new ArrayList&lt;String&gt;();
          final ArrayList&lt;String&gt; results_id = new ArrayList&lt;String&gt;();
  
          @Override
          protected void onCreate(Bundle savedInstanceState) {
              super.onCreate(savedInstanceState);
              setContentView(R.layout.qs_faculty_location);
              final Intent c = new Intent(QSFacultyLocation.this, QSLocationDetail.class);
  
              //------------------------------------------------------------------
              // Link editText to layout item
              filterText = (EditText) findViewById(R.id.search_box);
              filterText.addTextChangedListener(filterTextWatcher);
  
              //------------------------------------------------------------------
              // Reading Poi      
              /*SearchKategori searchKategori = new SearchKategori();
              UkmLocation selectedKategori = searchKategori.getSelectedKategori();
              List&lt;UkmLocation&gt; locationList = null;*/
  
                Log.d("Reading", "Reading all Kategori ..");
                  List&lt;UkmLocation&gt; kategori = db.getCategoryFaculty();
  
              //------------------------------------------------------------------
              // Determine list POI with category
  
                  for(UkmLocation k : kategori) {
                      results.add(k.getName());
                      results_id.add(k.getID());
                  }
  
              //------------------------------------------------------------------
              // Set list arrayAdapter to adapter
              adapter = new ArrayAdapter&lt;String&gt;(this, R.layout.list_item, R.id.textView1,results);       
              setListAdapter(adapter);
  
              //------------------------------------------------------------------
              // Set ListView from ListActivity
              ListView lv = getListView();
              lv.setTextFilterEnabled(true);
  
              //------------------------------------------------------------------
              // Set click event from listView
              lv.setOnItemClickListener(new OnItemClickListener() {
                  public void onItemClick(AdapterView&lt;?&gt; parent, View view, 
                          int position, long id) {
                    // When clicked, show a toast with the TextView text
                    Toast.makeText(getApplicationContext(), ((TextView) view).getText(),
                        Toast.LENGTH_SHORT).show();
  
                    Log.d("test", "position:" + position);
  
                    Log.d("test", "actualname:" + db.getUkmLocationByName(adapter.getItem(position)).getName());              
  
                    // String poiID = results_id.get(position);
                    String poiID = db.getUkmLocationByName(adapter.getItem(position)).getID();
                    setSelectedPoi(poiID);
                    startActivity(c);
                  }
              }); 
  
  
              //------------------------------------------------------------------
              // Closing db (if any)
          //    db.close();
          }
  
          private TextWatcher filterTextWatcher = new TextWatcher() {
  
              public void afterTextChanged(Editable s) {
              }
  
              public void beforeTextChanged(CharSequence s, int start, int count,
                      int after) {
  
              }
  
              public void onTextChanged(CharSequence s, int start, int before,
                      int count) {
                  adapter.getFilter().filter(s);
              }       
          };
  
          @Override
          protected void onDestroy() {
              super.onDestroy();
              filterText.removeTextChangedListener(filterTextWatcher);
          }
  
          public UkmLocation getSelectedPoi() {
              return selectedPOI;
          }
  
          public void setSelectedPoi(String poiID) {
              selectedPOI = db.getUkmLocation(poiID);
              Log.d("test2", "_id:" + db.getUkmLocation(poiID).getID());
              Log.d("test2", "Name:" + db.getUkmLocation(poiID).getName());
              // Closing db
              db.close();
          }
  }
  </code></pre>
  
  <p>QuickSearchMenu.java</p>
  
  <pre><code>package com.example.ukmlocationsearching;
  
  import java.io.IOException;
  import com.example.ukmlocationsearching.R;
  import com.example.ukmlocationsearching.R.id;
  import com.example.ukmlocationsearching.R.layout;
  import com.example.ukmlocationsearching.R.menu;
  
  import android.os.Bundle;
  import android.app.Activity;
  import android.content.Intent;
  import android.database.SQLException;
  import android.util.Log;
  import android.view.Menu;
  import android.view.View;
  import android.view.View.OnClickListener;
  import android.widget.Button;
  
  
  public class QuickSearchMenu extends Activity implements OnClickListener {
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
  
          //---------------------------------------------------------------------------
          // Initiate database data    
              initiateDb();
  
          //---------------------------------------------------------------------------
              super.onCreate(savedInstanceState);
          setContentView(R.layout.quick_search_menu);
  
          View faculty = findViewById(R.id.button2);
          faculty.setOnClickListener(this);
  
          View researchInstitute = findViewById(R.id.button1);
          researchInstitute.setOnClickListener(this);
  
          View college = findViewById(R.id.button3);
          college.setOnClickListener(this);
  
          View admin = findViewById(R.id.button4);
          admin.setOnClickListener(this);
  
          View facility = findViewById(R.id.button5);
          facility.setOnClickListener(this);
      }
  
      @Override
      public boolean onCreateOptionsMenu(Menu menu) {
          // Inflate the menu; this adds items to the action bar if it is present.
          getMenuInflater().inflate(R.menu.quick_search_menu, menu);
          return true;
      }
  
      public void onClick(View v) {
          // TODO Auto-generated method stub
          switch (v.getId()) {
  
          case R.id.button1:
              Intent b1 = new Intent(this, QSResearch.class);
              startActivity(b1);
              break;
          case R.id.button2:
              Intent b2 = new Intent(this,QSFacultyLocation.class);
              startActivity(b2);
              break;
          /*case R.id.button3:
              Intent b3 = new Intent(this,QuickSearchCollege.class);
              startActivity(b3);
              break;
          case R.id.button4:
              Intent b4 = new Intent(this,QuickSearchFaculty.class);
              startActivity(b4);
              break;
          case R.id.button5:
              Intent b5 = new Intent(this,QuickSearchCollege.class);
              startActivity(b5);
              break;*/
      }
  }
      //---------------------------------------------------------------------------
      // Initiate database data
      public void initiateDb() {
          DatabaseHandler myDbHandler =  new DatabaseHandler(this);
  
          try {
              myDbHandler.createDataBase();
          } 
          catch (IOException ioe) {
              throw new Error("Unable to create database");
          }
  
          try {
              myDbHandler.openDataBase();
          }
          catch(SQLException sqle) {
              throw sqle;
          }
          Log.d("Initiate", "UKM Location Count: " + myDbHandler.getUkmLocationCount());
          /*Log.d("Initiate", "Kategori Count: " + myDbHandler.getKategoriCount());
          Log.d("Initiate", "KategoriPoi Count: " + myDbHandler.getKategoriPoiCount());*/
          myDbHandler.close();
      }
  
      //------------------------------------------------------------------------------
  
  }
  </code></pre>
  
  <p>please do help me solve this. thank you</p>