You need to set a listener to the ListView. setOnItemClickListener and launch your new screen/activity from there...
On Tue, Oct 12, 2010 at 12:07 AM, Varun Khanduja <[email protected]>wrote: > Hello all, > > I was just wondering if someone can me understand how we can make a > new screen work in a existing code. I tried this tutorial but the part > which I don't understand very well is where should I put that piece of > java code in my existing code. Rest of it is fairly simple. Some help > please. Thanks > > > package com.varun.HelloListView; > > import java.util.ArrayList; > import java.util.HashMap; > > import android.app.ListActivity; > import android.os.Bundle; > import android.view.Menu; > import android.view.View; > import android.widget.Button; > import android.widget.SimpleAdapter; > import android.widget.TextView; > > public class HelloListView extends ListActivity { > TextView selection; > > ArrayList<HashMap<String, String>> list1 = new > ArrayList<HashMap<String, String>>(); > SimpleAdapter smipleAdapter1; > > ArrayList<HashMap<String, String>> list2 = new > ArrayList<HashMap<String, String>>(); > SimpleAdapter smipleAdapter2; > > ArrayList<HashMap<String, String>> bottom= new > ArrayList<HashMap<String, String>>(); > SimpleAdapter simpleAdapter3; > > > @Override > public void onCreate(Bundle icicle) { > super.onCreate(icicle); > > setContentView(R.layout.main); > > > smipleAdapter1 = new SimpleAdapter(this, > > list1, > > R.layout.list_item, > > new String[] {"line1", "line2"}, > > new int[] {R.id.label1, R.id.label2}); > smipleAdapter2 = new SimpleAdapter(this, > > list2, > > R.layout.list_item, > > new String[] {"line1", "line2"}, > > new int[] {R.id.label1, R.id.label2}); > > > > //pupulate the lists > addItems(); > > this.setListAdapter(smipleAdapter1); > // button click > Button next1 = (Button) findViewById(R.id.Button1); > next1.setOnClickListener( > new View.OnClickListener() { > public void onClick(View view) { > setListAdapter(smipleAdapter1); > > smipleAdapter1.notifyDataSetChanged(); > } > } > ); > this.setListAdapter(smipleAdapter2); > Button next2 = (Button) findViewById(R.id.Button2); > next2.setOnClickListener( > new View.OnClickListener() { > public void onClick(View view) { > setListAdapter(smipleAdapter2); > > smipleAdapter2.notifyDataSetChanged(); > } > } > ); > > > } > > > private void addItems() { > long ts = System.currentTimeMillis(); > int lastDigit = (int)( ts % 10 ); > > for(int i = 0; i < AndroidPhones1.length; i++) { > HashMap<String,String> item = new > HashMap<String,String>(); > item.put( "line1", AndroidPhones1[i] ); > item.put( "line2", "lastDigit: "+Integer.toString( > lastDigit ) ); > list1.add( item ); > smipleAdapter1.notifyDataSetChanged(); > } > > for(int i = 0; i < AndroidPhones2.length; i++) { > HashMap<String,String> item = new > HashMap<String,String>(); > item.put( "line1", AndroidPhones2[i] ); > item.put( "line2", "varun1" ); > > list2.add( item ); > smipleAdapter2.notifyDataSetChanged(); > } > > } > > @Override > public boolean onCreateOptionsMenu(Menu menu) { > super.onCreateOptionsMenu(menu); > > menu.add(0, Settings.ENTER_FOOD, 0, "Enter Food"); > menu.add(0, Settings.ANALYZE_FOOD, 0, "Analyze Food"); > menu.add(0, Settings.SETTINGS, 0, "Settings"); > > return true; > } > > > static final String[] AndroidPhones1 = new String[] { > "HTC Evo 1G", "Google Nexus One", "Motorola Devour", > "Motorola CLIQ", "Samsung Galaxy S", "Motorola Droid", > "myTouch 3G Slide", "Droid Eris", "Motorola Backflip", > "Motorola i1", "HTC Hero", "myTouch 3G Fender", > "HTC Droid Incredible", "Samsung Moment", "LG Ally " > }; > > static final String[] AndroidPhones2 = new String[] { > "HTC Evo 2G", "Google Nexus One", "Motorola Devour", > "Motorola 2LIQ", "Samsung Galaxy S", "Motorola Droid", > "myTouch 3G Slide", "Droid Eris", "Motorola Backflip", > "Motorola i1", "HTC Hero", "myTouch 3G Fender", > "HTC Droid Incredible", "Samsung Moment", "LG Ally " > }; > > static final String[] AndroidPhones3 = new String[] { > "HTC Evo 3G", "Google One", "Motorola Devour", > "Motorola 2LIQ", "Samsung Galaxy S", "Motorola Droid", > "myTouch 3G Slide", "Droid Eris", "Motorola Backflip", > "Motorola i1", "HTC Hero", "myTouch 3G Fender", > "HTC Droid Incredible", "Samsung Moment", "LG Ally ", > }; > > static final String[] AndroidPhones4 = new String[] { > "HTC Evo 4G", "Google Nexus hello", "Motorola Devour", > "Motorola 2LIQ", "Samsung Galaxy S", "Motorola Droid", > "myTouch 3G Slide", "Droid Eris", "Motorola Backflip", > "Motorola i1", "HTC Hero", "myTouch 3G Fender", > "HTC Droid Incredible", "Samsung Moment", "LG Ally " > }; > } > > -- > You received this message because you are subscribed to the Google > Groups "Android Developers" group. > To post to this group, send email to [email protected] > To unsubscribe from this group, send email to > [email protected]<android-developers%[email protected]> > For more options, visit this group at > http://groups.google.com/group/android-developers?hl=en -- Kumar Bibek http://techdroid.kbeanie.com http://www.kbeanie.com -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/android-developers?hl=en

