How to open or simulate a click on android ListPreference, which is inside the preferences category?

I am trying to open programmatically the ListPreference that exist inside the PreferenceCategory. The XML structure looks something like this:

<PreferenceScreen 
    android:key="pref_screen" >

    <PreferenceCategory 
        android:title="Category"
        andorid:key="pref_category">
        <ListPreference
            android:key="pref_list"
            android:title="List" />
    </PreferenceCategory>
</PreferenceScreen> 

My goal is to open the "pref_list" programmatically and display it to the user. I looked through this thread suggesting this solution:

// the preference screen your item is in must be known
PreferenceScreen screen = (PreferenceScreen) findPreference("pref_screen");

// the position of your item inside the preference screen above
int pos = findPreference("pref_list").getOrder();

// simulate a click / call it!!
screen.onItemClick( null, null, pos, 0 ); 

This works fine for a PreferenceScreen without a PreferenceCategory, but I can't get it to work for my case (when the ListPreference is inside the PreferenceCategory).

How can I change this for my case? Or is there another solution?

PreferenceCategory , onItemClick() PreferenceScreen. "pos" getOrder() PreferenceCategory .

+5
2

, , , this one

    ListAdapter listAdapter = getPreferenceScreen().getRootAdapter();

    for (int itemNumber = 0; itemNumber < listAdapter.getCount(); itemNumber++)
        if (listAdapter.getItem(itemNumber).equals(findPreference("pref_list")))
            getPreferenceScreen().onItemClick(null, null, itemNumber, 0);
0

, :

View.getLocationOnScreen() / getLocationInWindow(), . , width a height .

    MotionEvent me=MotionEvent.obtain(0, 0, MotionEvent.ACTION_DOWN, width, height, 0);
    rootView.dispatchTouchEvent(me);
    me=MotionEvent.obtain(0, 0, MotionEvent.ACTION_UP, width, height, 0);
    rootView.dispatchTouchEvent(me);
    me.recycle();
-1

All Articles