Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android ListView with onClick items

I'm a new programmer and new in Android. I'm using this example http://www.androidhive.info/2012/09/android-adding-search-functionality-to-listview/ and it works great.

Now I want to make the items (Dell, Samsung Galaxy S3, etc) to call a function to open a new activity with different information each.

For example:

If I touch Dell, a new Activity has to show up showing me information about Dell. If I touch Samsung, the same thing.

I Googled but couldn't find anything helpfull, any hint? I think this is basic, but I'm new so I don't really know where to start

like image 891
Agustín Avatar asked Jan 22 '14 22:01

Agustín


2 Answers

In your activity, where you defined your listview

you write

listview.setOnItemClickListener(new OnItemClickListener(){        @Override     public void onItemClick(AdapterView<?>adapter,View v, int position){         ItemClicked item = adapter.getItemAtPosition(position);          Intent intent = new Intent(Activity.this,destinationActivity.class);         //based on item add info to intent         startActivity(intent);     } }); 

in your adapter's getItem you write

public ItemClicked getItem(int position){     return items.get(position); } 
like image 197
Lena Bru Avatar answered Oct 06 '22 23:10

Lena Bru


lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {     @Override     public void onItemClick(AdapterView<?> parent, View view, int position, long id) {          Intent i = new Intent(getActivity(), DiscussAddValu.class);         startActivity(i);     } }); 
like image 45
Munna Sharma Avatar answered Oct 07 '22 00:10

Munna Sharma