0

Im trying to retrieve the position of the pressed button, in a list of Preference. My class extends PreferenceActivity. This is my code:

ListView listView = getListView();
    listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        public void onItemClick(AdapterView<?> av, View view, int i, long l) {
            Toast.makeText(Activity.this, "myPos "+i, Toast.LENGTH_LONG).show();
        }
    });

My XML goes like this

<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
        <Preference
        android:key="key1"
        android:title="string1"
        android:summary="summary1"
        android:icon="@drawable/someicon"/>
        <Preference
        android:key="key2"
        android:title="string2"
        android:summary="summary2"
        android:icon="@drawable/someicon2"/>
        ...
</PreferenceScreen>

Im getting nothing on toast, so onItemClickListener is not being invoked.

Thanks in Advance.

EDIT: Thanks for not answering, that way I answered myself :D

  • If you found the solution your self, can you please post the answer for others. This way if someone else has the same issue, it may assist them as well. If you do not want to post the answer, then just delete the question. – prolink007 Apr 08 '12 at 19:14
  • I just made a for loop, for instantiating each preference `onPreferenceClick` – Jesus David Gulfo Agudelo Apr 11 '12 at 01:37

1 Answers1

0

I couldn't solve this by the OnItemClickListener way, so I went for a loop for assign to each preference a onPreferenceClick