开发者

Providing my own list view for a prefrence activity

开发者 https://www.devze.com 2023-03-24 18:10 出处:网络
I havea class which extends from ListView. I add开发者_如何学运维ed some extra functionality(drag and drop) for this new class. My question is there any way i can use this extended ListView class in a

I have a class which extends from ListView. I add开发者_如何学运维ed some extra functionality(drag and drop) for this new class. My question is there any way i can use this extended ListView class in a preference activity.

I need to provide drag and drop functionality for a legacy preference activity.


Are you asking if it's possible to open an arbitrary activity from a clicked item in a preference activity? If so, you need to do two things. First, add a PreferenceScreen item to your preferences xml file:

<PreferenceScreen
    android:key="CUSTOM_ACTIVITY_KEY"
    android:title="Title"
    android:summary="Summary" />

Then in your settings activity's onCreate:

Preference pref = getPreferenceScreen().findPreference("CUSTOM_ACTIVITY_KEY");
final Intent intent = new Intent(this, CustomActivity.class);
if (pref != null)
{
    pref.setOnPreferenceClickListener(new OnPreferenceClickListener()
    {
        public boolean onPreferenceClick(final Preference preference)
        {
            startActivity(intent);

            return false;
        }
    });
}


If running a custom activity off of a PreferenceScreen item isn't enough, the only other option I could think of is to roll your own Preferences implementation. Someone else should correct me if I'm mistaken, but I think it might be possible to pull the Preferences source and modify accordingly.


I came across another API in

android.preference.PreferenceScreen.bind(ListView listView)

Binds a ListView to the preferences contained in this PreferenceScreen via getRootAdapter(). So after inflating the layout file, we will be able to attach the our custom listview to this the preferenceScreen of the activity.

0

精彩评论

暂无评论...
验证码 换一张
取 消