我迁移到android.support.v7.preference,我对ListPreference项有一些问题。
我有那段代码:
public class CurrencyListPreferences extends ListPreference {
private List<Currency> mCurrencyList;
private Context mContext;
public CurrencyListPreferences(Context context) {
this(context, null);
}
public CurrencyListPreferences(Context context, AttributeSet attrs) {
super(context, attrs);
this.mContext = context;
}
public void setCurrencyList(List<Currency> currencyList) {
this.mCurrencyList = currencyList;
}
protected void onPrepareDialogBuilder(Builder builder) {
final ListAdapter listAdapter = (ListAdapter) new CurrencyAdapter(mContext, mCurrencyList, this);
builder.setPositiveButton(null, null);
builder.setAdapter(listAdapter, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
}
});
}
public String getText() {
return Preferences.getStringValue(mContext, TypePreference.TYPE_CURRENCYCODE);
}
}
然后我有一个货币适配器,显示所需的不同值
当我迁移到android.support.v7.preference时,该代码不起作用。我有一条消息“ListPreference需要一个条目数组和一个entryValues数组。”
onPrepareDialogBuilder不再被调用,有没有办法迁移我的旧代码?
如果没有解决方案,我想到了两个解决方案:
此致