Win a copy of Murach's MySQL this week in the JDBC and Relational Databases forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

listview item click

 
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Saloon Keeper
Posts: 7573
176
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 37
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Saloon Keeper
Posts: 7573
176
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 37
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Saloon Keeper
Posts: 7573
176
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 37
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Saloon Keeper
Posts: 7573
176
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 37
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks alot man, i was stuck i really do not know why,
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic