Answer the question
In order to leave comments, you need to log in
How to handle clicks on a ListView item?
Created a custom listView based on data from a MySql table. There is no way to write a click handler for a list item.
The ListView row consists of three TextViews. It is necessary, when clicking on the corresponding TextView, to call the DialogFragmet, in which to make changes, write them to the database and update the ListView.
I fill the ListView with the following method:
Cursor c = db.query("rdtable", null, null, null, null, null, null);
ArrayList<Map<String, Object>> data;
String[] from;
int[] to;
Map<String, Object> m;
data = new ArrayList<Map<String, Object>>();
if (c.moveToFirst()) {
do {
m = new HashMap<String, Object>();
m.put(ATTRIBUTE_NAME_DISTANCE, c.getDouble(1));
m.put(ATTRIBUTE_NAME_PERCENT, c.getInt(3));
m.put(ATTRIBUTE_NAME_SPEED, c.getDouble(5));
data.add(m);
} while (c.moveToNext());
from = new String[]{ATTRIBUTE_NAME_DISTANCE, ATTRIBUTE_NAME_PERCENT, ATTRIBUTE_NAME_SPEED};
to = new int[]{R.id.distance, R.id.percent, R.id.speed};
SimpleAdapter sAdapter = new SimpleAdapter(this, data, R.layout.mylistitem, from, to);
rdlistview.setAdapter(sAdapter);
public class TwoActivity extends Activity implements View.OnClickListener, SeekBar.OnSeekBarChangeListener, AdapterView.OnItemClickListener {
...
rdlistview = (ListView) findViewById(R.id.rdlistView);
rdlistview.setOnItemClickListener(this);
...
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
Log.d(LOG_TAG, "checked: " + rdlistview.getCheckedItemPosition());
}
Answer the question
In order to leave comments, you need to log in
I can’t even imagine what kind of language it is (I can only assume that it’s some kind of C-oriented one), but nevertheless I see the declaration of the onItemClick function , but I can’t find its call. Maybe it's hidden somewhere and you haven't copied it here?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question