getSelectedPosition(). This won't work in touch mode though, since the selection disappears when the user touches the screen.
On Wed, May 13, 2009 at 12:38 PM, Vinicius Santos <viniciu...@gmail.com> wrote: > Dear all, I'm having trouble to get the index of the active highlighted Item > on a List View. > > Please, help me to get the index of the highlighted item > > public class HelloForm extends Activity { > > > ListView lv; // my listview > > /** Called when the activity is first created. */ > @Override > public void onCreate(Bundle savedInstanceState) { > > super.onCreate(savedInstanceState); > setContentView(R.layout.main); > > lv = (ListView)findViewById(R.id.myListView); > > ArrayAdapter<String> aa = new > ArrayAdapter<String>(getApplicationContext(), > android.R.layout.simple_list_item_1, > COUNTRIES); > lv.setAdapter(aa); > > final ImageButton button = (ImageButton) > findViewById(R.id.android_button); > button.setOnClickListener(new ImageButton.OnClickListener() { > public void onClick(View v) { > > > int position = / /HERE IS THE PROBLEM, HOW CAN I GET THE > HIGHLIGHTED POSITION > > String country = (String)lv.getItemAtPosition(position); > > DBInterface db = new DBInterface(lv.getContext()); > db.open(); > long id_Text; > id_Text = db.insertTitle(country); > db.close(); > if(id_Text == -1 ) > Toast.makeText(HelloForm.this, "Error writing DB", > Toast.LENGTH_SHORT).show(); > // Perform action on clicks > // Toast.makeText(HelloForm.this, "Beep Bop", > Toast.LENGTH_SHORT).show(); > } > }); > > final ImageButton button_red = (ImageButton) > findViewById(R.id.android_button_red); > button_red.setOnClickListener(new ImageButton.OnClickListener() { > > public void onClick(View v) { > > DBInterface db = new DBInterface(v.getContext()); > //---get all titles--- > db.open(); > Cursor c = db.getAllCountries(); > if (c.moveToFirst()) > { > do { > DisplayTitle(c); > } while (c.moveToNext()); > } > db.close(); > // Perform action on clicks > // Toast.makeText(HelloForm.this, "Beep Bop", > Toast.LENGTH_SHORT).show(); > } > }); > } > > > > -- Romain Guy Android framework engineer romain...@android.com Note: please don't send private questions to me, as I don't have time to provide private support. All such questions should be posted on public forums, where I and others can see and answer them --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -~----------~----~----~----~------~----~------~--~---