ListView & onItemClick - When click, open new activity

310 Views Asked by At

actually my ListView is here:

ListView lv = (ListView) findViewById(android.R.id.list);                 
ArrayAdapter<String> ad = new ArrayAdapter<String>(getApplicationContext(),android.R.layout.simple_list_item_1,ls);

lv.setAdapter(ad);

What I want is when I click on an item in my ListView it should open a new activity for that item where I can show some description of the item e.g. if the item would be a BMW M6 than in the new acticity should be things like hp, 0-100 etc.

How can I do that?

1

There are 1 best solutions below

0
On BEST ANSWER

To start a new Activity you have to use intents :

 Intent intent = new Intent(this, MySecondActivity.class);

You can add extras :

 intent.putExtra(EXTRA_MESSAGE, message);

And to start the activity :

startActivity(intent);

Now if you wan to do it when you click on an item of your list you'll have to use :

myList.setOnItemClickListener();