Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

listview item click

 
johnson dubula
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ood day guys

i have created a custom listview with pictures and text, now i want to open an activity for each item on the list, how do i do that? i know how to toast i just dont know how to open a new activity for each item on the listview. bellow is my Code
 
Tim Moores
Bartender
Posts: 3134
50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The first result I get by searching for "android starting an activity" is https://developer.android.com/training/basics/firstapp/starting-activity.html, which looks very promising.
 
johnson dubula
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
good day Tim

i know how to use intents to open new activities,send sms and email, i dnt know how to do it with a list view. you see a in a button you just create a button and use its ID e.g (for imageButtons)

ImageButton buttonConDBN= (ImageButton) findViewById(R.id.buttonConDBN);
buttonConDBN.setOnClickListener(
new ImageButton.OnClickListener() {
@Override
public void onClick(View v) {
Intent i = new Intent(ContactUs.this, DBN.class);
startActivity(i);
}
}


);

now with a listview there are more that one items, so how do you specify which one and create its intent
 
Tim Moores
Bartender
Posts: 3134
50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What do you mean by "which one"? The position parameter tells you which item was clicked on.
 
johnson dubula
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I get you Tim, but how do i say the third one,or forth one.
Car clickedCar=myCars.get(position);
 
Tim Moores
Bartender
Posts: 3134
50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry, I'm not following. You have the position parameter, so what prevents you from using it in whatever way you need to? What is the precise problem you're stuck on? The code line with cars doesn't make things clear without explanation.
 
johnson dubula
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
good day Tim

i want to open a new activity when someone clicks on the 3rd car on the list.
where do i write the 3 (or 2 since it will start from zero counting)

Car clickedCar=myCars.get(position);
 
Tim Moores
Bartender
Posts: 3134
50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You would check the position parameter:



Or, more likely, you would use a case statement, since presumably you want to do something for other values as well.
 
johnson dubula
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks alot man, i was stuck i really do not know why,
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic