Select all text on selectAll () popup menu

I use the selectAll () function, but it does nothing at all. Is there a way to select text so that it doesn't come back and then repeat?

void GetQuantity()

{
    AlertDialog.Builder alert = new AlertDialog.Builder(this);
    alert.setTitle("Quantity");
    alert.setMessage("Enter Quantity");

    final EditText input = new EditText(this);

    alert.setView(input);
    input.setText("1");

    // android:selectAllOnFocus="true"

    input.setInputType(InputType.TYPE_CLASS_NUMBER);


    input.selectAll();

    alert.setPositiveButton("OK", new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            Quantity =Double.parseDouble( input.getText().toString());
            btnQuan.setText(input.getText().toString());

        }
    });


    alert.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int whichButton) {
            // do nothing
        }
    });
    alert.show();

}
+3
source share
4 answers

I ended up writing a class to get numbers and added a spinner too. that way I have 100% control over what happens.

0
source

The actual solution to the problem is this:

for any EditText that you want to use the selectAll () method on, you must declare it BufferType as TextView.BufferType.SPANNABLE. this allows you to fetch for a spannable object. see the Spannable, EditText, and Selection classes for more information. here is a software example:

myEditText.setText("mytext", TextView.BufferType.SPANNABLE);
myEditText.selectAll();

bufferType xml, android: bufferType.

+4

NumberPicker API 11.

EditText, :

  • .xml :

    Android: selectAllOnFocus = ""

  • OnFocusChangeListener:

    myEditText.setOnFocusChangeListener( OnFocusChangeListener() {   @Override   public void onFocusChange (View v, boolean hasFocus) {     if (hasFocus) {       ((EditText) v).selectAll();     }   }});

0

, ( # Xamarin, Java):

private void InitFocus()
{
    Java.Lang.Runnable rable = new Java.Lang.Runnable(()=> 
    {
        EditText maleCount = FindViewById<EditText>(Resource.Id.txtMaleCount);
        maleCount.RequestFocus();
        maleCount.SelectAll();
    });
    new Handler().Post(rable);
}

, , .

0
source

Source: https://habr.com/ru/post/1785544/


All Articles