Activity with two Layouts and FocusText focusable

1

My app only has one activity but two Layouts.

The switching between the two Layouts is done through a Button that exists in each of the Layouts.

In Layout 1 there is a% num of type numeric and in Layout 2 there is another EditText but type text .

The two EditTexts have the focusable property active, but when I switch between Layouts the keyboard type does not change automatically, ie to change the type of keyboard I have to click on the EditText of this Layout.

I have tried in java code to insert the line EditText but it does not work.

    
asked by anonymous 10.05.2015 / 12:30

1 answer

1

Easy, very easy:

edittext2.requestFocus();

Here is the complete code:

public class MainActivity extends AppCompatActivity {

    Button botao1;
    Button botao2;
    EditText edittext1;
    EditText edittext2;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Layout_1();
    }

    public void Layout_1() {
        setContentView(R.layout.layout_1);
        botao1 = (Button) findViewById(R.id.button1);
        edittext1 = (EditText) findViewById(R.id.editText1);
        edittext1.requestFocus();
        botao1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Layout_2();
            }
        });

    }

    public void Layout_2() {
        setContentView(R.layout.layout_2);
        botao2 = (Button) findViewById(R.id.button2);
        edittext2 = (EditText) findViewById(R.id.editText2);
        edittext2.requestFocus();
        botao2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Layout_1();
            }
        });
    }
}
    
10.05.2015 / 15:34