2012-08-27 13 views

回答

2

要回答我的問題:

首先,在PreferenceScreen,你需要的狀態: < full.path.to.your.OwnLayoutClass 機器人:名字= 「whatevever」 機器人:dialogLayout = 「@ layout/your_own_layout」/ >

your_own_layout可以是任何你想要的,按鈕,editTexts,根據你的願望linearlayout。

基本是表示您自己的偏好對話框的類。這裏是如何做到這一點簡單的例子:

public class YourOwnLayoutClass extends DialogPreference { 

    private LinearLayout mView; 

    public YourOwnLayoutClass(Context context, AttributeSet attrs) { 
     super(context, attrs); 
     setPersistent(false); 
     setDialogLayoutResource(R.layout.your_own_layout); 
    } 

    @Override 
    protected void onBindDialogView(View view) { 
     super.onBindDialogView(view); 
     mView = (LinearLayout) view; 
    } 

    @Override 
    protected void onDialogClosed(boolean positiveResult) { 
     super.onDialogClosed(positiveResult); 

     if (positiveResult) { 
      // get value from editFields, do whatever you want here :) 
      // you can acces them through mView variable very easily 
     } 
    } 
} 

重要的參考價值: I need to have a custom dialog in Preferences

Concise way of writing new DialogPreference classes?

Android: launch a custom Preference from a PreferenceActivity