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?

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
vivek_Android
  • 1,697
  • 4
  • 26
  • 43
  • 1
    What part are you having trouble with? Knowing a click occurred, determining which item was clicked, or starting a new activity? – Mark B Oct 08 '10 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. – Maragues Oct 08 '10 at 11:41

3 Answers3

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.
    }
});
Eliasz Kubala
  • 3,836
  • 1
  • 23
  • 28
Tony
  • 1,581
  • 11
  • 24
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();


        }
    });
}
Ivan Ferić
  • 4,725
  • 11
  • 37
  • 47
Annadurai
  • 21
  • 1
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);
Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
Maragues
  • 37,861
  • 14
  • 95
  • 96