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();
}
});
}
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---