Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dynamic content for Android layout

Pardon the question title because I'm not really sure of the right term(s) to use. I am just familiarizing myself with ListView and what I want to do is this:

-Suppose I have a Dog class which has String name, String breed, and int age.

-I would then make many instances of Dog and put them into a ListView which displays only their names.

-I would also have one layout, lets say doginfo.xml, that has the text "Name:", "Breed:", and "Age:".

So how can make the values of the clicked item (ie: name, breed, age) display on the next activity, which is doginfo.xml?

like image 471
10834346 Avatar asked May 11 '26 12:05

10834346


1 Answers

I'm presuming you have an array/arraylist of your dogs and you are adding them in order to your listview. Check out the onItemClickListener of this exmaple in the android doc:

http://developer.android.com/resources/tutorials/views/hello-listview.html

In your click listener use "int position" to get the object from your array/arraylist. Once you have this information, you can pass it easily between activities using "bundle.putString()" and "b.getString()".

Look at this simple tutorial for information on passing data between activities:

http://thedevelopersinfo.wordpress.com/2009/10/15/passing-data-between-activities-in-android/

like image 194
NotACleverMan Avatar answered May 13 '26 00:05

NotACleverMan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!