I want put a button on android edittextpreference.
I create a custom editextpreference:
public class EditTextPreferenceWithButton extends EditTextPreference {
private Context context;
public EditTextPreferenceWithButton(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
this.context=context;
}
public EditTextPreferenceWithButton(Context context, AttributeSet attrs) {
super(context, attrs);
this.context=context;
}
public EditTextPreferenceWithButton(Context context) {
super(context);
this.context=context;
}
@Override
protected void onBindDialogView(View view) {
super.onBindDialogView(view);
view.setLayoutParams(new LayoutParams(android.view.ViewGroup.LayoutParams.WRAP_CONTENT, android.view.ViewGroup.LayoutParams.WRAP_CONTENT));
final EditText editText = (EditText)view.findViewById(android.R.id.edit);
ViewGroup vg = (ViewGroup)editText.getParent();
Button button = new Button(context);
vg.addView(button,ViewGroup.LayoutParams.WRAP_CONTENT,
ViewGroup.LayoutParams.WRAP_CONTENT);
}
}
In this way the button is show below the edit text, but I want it is next the edittext like this:
|EditText| |Button|
Please help me!
Thank you
I would create a subclass of
DialogPreference.I’m assuming you’re going to persist the value in the
EditTextand I’m leaving the action of the button up to you. See this post for more information on the in’s and out’s of extendingDialogPreference.In order to get the key into the
SharedPreferences, put the following in your XML: