Custom layout ListPreference

后端 未结 3 1629
深忆病人
深忆病人 2021-01-14 19:39

Prompt please where it is possible to read about creating a custom layout listpreference ( background and layout top panel, panel button ). Met - examples only for custom ro

3条回答
  •  没有蜡笔的小新
    2021-01-14 20:01

    in your preference.xml file you can refer to your custom ListPreference by the full name of the class i.e. com.example.MyPreference

    
    
        
        
    
    

    Then your class MyPreference hould be something like this:

    import android.preference.ListPreference;
    
    public class MyPreference extends ListPreference  {
    
        Context context;
    
        public MyPreference(Context context, AttributeSet attrs) {
            this.context = context;
            setDialogLayoutResource(R.layout.yourLayout); //inherited from DialogPreference
            setEntries(new CharSequence[] {"one", "two"});
            setEntryValues(new CharSequence[] {"item1", "item2"});
        }
        protected void onDialogClosed(boolean positiveResult) {
        Toast.makeText(context, "item_selected",
                           Toast.LENGTH_SHORT).show();
        }
    }
    

提交回复
热议问题