0

Android OSのwifi-settingsがネットワークのリストに持っているものと同様のPreferenceActivityにlistViewを表示したい(例はここ、画像の下部にあります)。ただし、そのようなことは利用できないため、Preference を拡張する新しいクラスを作成しました。onCreateView で返されたのは単なる ListView インスタンスです。

それは機能しましたが、listViewは、layoutParamsに何をしても、アダプターに何をしても、約1つのアイテムの一定のサイズです。onCreateView 内にアダプターを設定しても、まったく同じサイズです。

それだけでなく、listView 内に複数の項目があることが明らかな場合でも、listView をスクロールできません。

もちろん、ネイティブな感じを与えるために、すべての設定と同じテキストサイズ標準を使用したいと思います。

うまく機能させるために何ができるか教えてください。

ところで、アプリは Android API 10+ (最小 10) で動作するはずです。

4

2 に答える 2

2

In case you are going for the same appearance / behavior, you should stay with the plain PreferenceActivity implementation, and add the new preference items into the "list" dynamically from code (eventually with custom renderers).

A basic implementation of such display would be:

/**
 * This variable stands for the items with which you want to populate the list
 */
final HashMap<String, String> networks = new HashMap<String, String>();

final PreferenceCategory cat = new PreferenceCategory(getApplicationContext());
cat.setTitle(R.string.wifinetworks); // holding "Wi-fi networks"
for (final String networkTitle : networks.keySet())
{
    final Preference pref = new Preference(getApplicationContext());
    pref.setTitle(networkTitle);
    pref.setSummary(networks.get(networkTitle));
    cat.addPreference(pref);
}

Edit: For adding custom components to an existing PreferenceActivity, you should give a try to the addContentView method. From within onCreate:

final LayoutParams params = new LayoutParams(LayoutParams.FILL_PARENT, 
        LayoutParams.WRAP_CONTENT);
addContentView(buttonBar, params);
于 2012-05-16T10:28:50.900 に答える
0

わかりました、答えは setContentView を任意のレイアウト (希望するビューを含む) に使用し、そこに設定用の listView を追加し、この listView に対して bind と setAdapter を呼び出すことです。

次のような他のソリューションを見て、このソリューションを見つけました: http://kmansoft.com/2011/08/29/implementing-long-clickable-preferences/

于 2012-05-16T13:35:58.797 に答える