views:

106

answers:

1

i want to show this array as a listview in a new screen when a button is clicked.

ArrayList<String> favorite = new ArrayList<String>();  

this ListView is a small part of my class. i cant seem to figure out how to implement it with my code (i can figure out how to create a listview in a separate application, and set the onitemclicklistner just for that listview) i want to display that listview when.

case R.id.ShowFavButton:
A: 

Your question isn't entirely clear.... but you would build a separate Activity, possibly subclassing ListActivity (documentation here), and then load it when you click on the button. If your Activity was named FavoritesActivity, it would be something like this:

Button fav = (Button)findViewById(R.id.ShowFavButton);
fav.setOnClickListener(new View.OnClickListener() {
     public void onClick(View v) {
         startActivity(new Intent(FirstActivity.this, FavoritesActivity.class));
     }
});

If you want to return something from your FavoritesActivity to your FirstActivity (or whatever it is called), you can use startActivityForResult instead of just startActivity.

synic
let me see if i can clear it up.i have data in the string array "favorite" i want to display this data in a new view(defined in layout folder called listview.xml which has my predefined layout,with a listview. i want to populate that listview with the strings in that "favorite" stringarray. i want to do this by clicking that R.id.ShowFavButton.
zaid
Yes, then you want a new Activity. Each "screen" in Android is a new Activity (for the most part)
synic
okay did not realize i have to have a new Activity, thanks for the help.
zaid