ListView: should open a new activity
===

Hello, Everybody. I'm a newbie. My goal is when I want to click on a specific item from the ListView, it should open a new activity that I've programmed. For example: when I click on "John", I wish it opens a class called X, Mary, should open a class Y, Charlie, class Z, so on. I've tried using a "onListItemClick" code at the end of the code, but it doesn't work. Nothing happens when I click on John's name from ListView app. Please, where my code is wrong and help me where I should put the code and what the correct code is.

P.S: I declared all activities on Manifest file

This is my code that I'm using:

    public class Searchsort extends Activity {
        
        private ListView lv1;
        private EditText ed;
        private String lv_arr[]={"John","Mary","Carl","Rose","Charlie","Allan", "João"};
        private ArrayList<String> arr_sort= new ArrayList<String>();
        int textlength=0;

        /** Called when the activity is first created. */
        @Override
        public void onCreate(Bundle icicle) {
            super.onCreate(icicle);
            setContentView(R.layout.main);
            lv1 = (ListView)findViewById(R.id.ListView01);
            ed = (EditText)findViewById(R.id.EditText01);

            // By using setAdpater method in listview we an add string array in list.

            lv1.setAdapter(new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1 ,   lv_arr));
            ed.addTextChangedListener(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) {
                    textlength=ed.getText().length();
                    arr_sort.clear();
                    for(int i=0;i<lv_arr.length;i++) {
                        if(textlength<=lv_arr[i].length()) {
                            if(ed.getText().toString().equalsIgnoreCase((String) lv_arr[i].subSequence(0,  textlength))) {
                                arr_sort.add(lv_arr[i]);
                            }
                        }
                    }

                    lv1.setAdapter(new ArrayAdapter<String>  (Searchsort.this,android.R.layout.simple_list_item_1 , arr_sort));

                }
            });
        }

        public void onListItemClick(ListView parent, View v, int position, long id) {
            if ("John".equals(lv_arr[position])) { 
                Intent myIntent = new Intent(Searchsort.this, X.class);
                startActivity(myIntent);

            if ("Mary".equals(lv_arr[position])) { 
                Intent myIntent = new Intent(Searchsort.this, Y.class);
                startActivity(myIntent);

            if ("Charlie".equals(lv_arr[position])) { 
                Intent myIntent = new Intent(Searchsort.this, W.class);
                startActivity(myIntent);


            }
        }

    }

 

