kaushikSuman
kaushikSuman

Reputation: 401

not initiating another activity in listview click

The is my code.I am here pupulating a list view with some array data.when I am hitting the list I can be able to detect it by using a Toast.But I can't able to call another activity. in the place of Toast event.
public class ListView extends ListActivity {

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setListAdapter(new ArrayAdapter<String>(this, R.layout.foodjoint, RESTAURANTS));

    android.widget.ListView lv = getListView();
    lv.setTextFilterEnabled(true);


    lv.setOnItemClickListener(new OnItemClickListener() {
        public void onItemClick(AdapterView<?> 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();
            myClickHandler();
        }
    });

    //      ListView restuList=ListView();

}

static final String[] RESTAURANTS = new String[] {
    "Restaurant 1", "Restaurant 2", "Restaurant 3", "Restaurant 4", "Restaurant 5",
    "Restaurant 6", "Restaurant 7", "Restaurant 8", "Restaurant 9", "Restaurant 10",
    "Restaurant 11", "Restaurant 12", "Restaurant 13", "Restaurant 14", "Restaurant 15"
};
public void myClickHandler() {
    finish();
    Intent gotoLIst=new Intent(ListView.this,MenuActivity.class);
    startActivity(gotoLIst);
}

and here is my XmL file

<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@color/AliceBlue "
    android:padding="10dp"
    android:textSize="16sp"
    android:focusableInTouchMode="false"
    android:clickable="false"
    android:focusable="false" >

I need to call another activity @ listView onitemClick.

Actually I have used another activity which also use some list-view.and that activity contains some error.that's why it's not working. Thnx to Luksprog for helping me to find the answer.

Upvotes: 1

Views: 214

Answers (1)

user
user

Reputation: 87064

You'll probably want to finish() the current Activity after you start the new one:

public void myClickHandler() {
    Intent gotoLIst=new Intent(ListView.this,MenuActivity.class);
    startActivity(gotoLIst);
    finish();
}

Upvotes: 1

Related Questions