2

I have a list view with 15 items. When I click on any item I want to change the screen(Intent). how can I change the activity on item selected in android? any tutorial or source code?

2
  • 1
    What part are you having trouble with? Knowing a click occurred, determining which item was clicked, or starting a new activity? Commented Oct 8, 2010 at 11:33
  • 2
    please, do a little bit of research yourself before asking a question. This same question (both the item clicked and the change activity) is answered more than 10 times just in SO. Commented Oct 8, 2010 at 11:41

3 Answers 3

6

You can use ListView's setOnItemClickListener, and start an new Activity in your implementation of this method. Following is sample code:

myListview.setOnItemClickListener(new AdapterView.OnItemClickListener() {
    public void onItemClick(AdapterView parent, View v, int position, long id){
        // Start your Activity according to the item just clicked.
    }
});
Sign up to request clarification or add additional context in comments.

Comments

2
final ListView list = (ListView) findViewById(R.id.SCHEDULE);

protected void onCreate(Bundle savedInstanceState) {
    list.setOnItemClickListener(new OnItemClickListener() {

        public void onItemClick(AdapterView<?> arg0, View arg1, int pos,
                long arg3) {
             Toast.makeText(getApplicationContext(),"hiihih",Toast.LENGTH_SHORT).show();


        }
    });
}

Comments

2

Check the selected answer in ListView OnItemClickListener Not Responding?

If you also need code examples to change activity, head to https://developer.android.com/guide/index.html and start reading.

// Prepare intent
Intent newActivity = new Intent(this, NewActivity.class);

// start activity
startActivity(newActivity);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.