title: How to create a Listview so that clicking on each list item will open different activity?
body: <p>I have a List view. I want to click on each list item and it would open different activity. Actually, I wrote the code, but its not working. My coding skills are unable to handle the issue. How to create a Hahmap with a string and a class pair and then put that into ArrayAdapter . Can any one please show me the code?</p>
  
  <p>ListViewAcivity.java</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.ArrayAdapter;
  import android.widget.ListView;
  import android.widget.Toast;
  
  import java.util.ArrayList;
  import java.util.HashMap;
  
  public class ListViewActivity extends Activity {
      ListView listView ;
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.main_screen_activity);
  
          // Get ListView object from xml
          listView = (ListView) findViewById(R.id.list);
  
          // Defined Array values to show in ListView
          HashMap&lt;String, Class&gt; hashMap=new HashMap&lt;String, Class&gt;();
  
  
           hashMap.put("A Function", MActivity.class);
           hashMap.put("B Function",AActivity.class);
           hashMap.put("c Function",XActivity.class);
           hashMap.put("D Function",ZActivity.class);
           hashMap.put("E Function", PActivity.class);
           hashMap.put("F Function", QActivity.class);
  
  
          // Define a new Adapter
          // First parameter - Context
          // Second parameter - Layout for the row
          // Third parameter - ID of the TextView to which the data is written
          // Forth - the Array of data
  </code></pre>
  
  <p>//error is here...... // this constructor can not be solved. //I don't know how to use    //String, Class pair with Array Adapter.</p>
  
  <pre><code>  ArrayAdapter&lt;HashMap&lt;String,Class&gt;&gt; adapter = new ArrayAdapter&lt;HashMap&lt;String,Class&gt;&gt;(this, android.R.layout.simple_list_item_1, android.R.id.text1, hashMap);
  
  
          // Assign adapter to ListView
          listView.setAdapter(adapter);
  
          // ListView Item Click Listener
          listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
  
              @Override
              public void onItemClick(AdapterView&lt;?&gt; parent, View view,
                                      int position, long id) {
  
                  // ListView Clicked item index
                  int itemPosition     = position;
  
                  // ListView Clicked item value
                  String  itemValue    = (String) listView.getItemAtPosition(position);
                  switch(itemPosition){
                      case 0:  Intent newActivity = new Intent(ListViewActivity.this, MActivity.class);
                          startActivity(newActivity);
                          break;
                      case 1:  Intent newActivity1 = new Intent(ListViewActivity.this, AActivity.class);
                          startActivity(newActivity1);
                          break;
                      case 2:  Intent newActivity2 = new Intent(ListViewActivity.this, XActivity.class);
                          startActivity(newActivity2);
                          break;
                      case 3:  Intent newActivity3 = new Intent(ListViewActivity.this, ZActivity.class);
                          startActivity(newActivity3);
                          break;
                      case 4:  Intent newActivity4 = new Intent(ListViewActivity.this, PActivity.class);
                          startActivity(newActivity4);
                          break;
                      case 5:  Intent newActivity5 = new Intent(ListViewActivity.this, QActivity.class);
                          startActivity(newActivity5);
                          break;
  
  
                  }
  
              }
              @SuppressWarnings("unused")
              public void onClick(View v){
              };
          });}
  }
  </code></pre>
  
  <p>main_screen_Activity.xml</p>
  
  <pre><code>&lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:orientation="vertical" &gt;
  &lt;ListView
      android:id="@+id/list"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"&gt;&lt;/ListView&gt;
  
  &lt;/LinearLayout&gt;
  </code></pre>