D
D
Denis Afonin2014-11-11 20:16:05
MySQL
Denis Afonin, 2014-11-11 20:16:05

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);

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

However, when the list item is clicked, nothing happens.
Tell me how to implement the idea?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
My joy, 2014-11-11
@t-alexashka

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?

O
one pavel, 2014-11-12
@onepavel

1. you made a mistake with the topic =)
2. do not mislead people - the code is in java
3. according to those pieces of code that I see, it is written correctly

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question