简体   繁体   English

单击下一步时如何更改EditTexts?

[英]How do I change EditTexts when clicking next?

I have an EditText box that appears and the hint in it is actually a question that needs to be answered. 我有一个EditText框出现,其中的提示实际上是一个需要回答的问题。 Once the user enters the value and hits next, how can I make a different EditText box take the originals place. 一旦用户输入了值并点击下一步,我该如何使另一个EditText框取代原始位置。 I want to do this so there is a new hint(question) and I can manipulate that input differently than with the first input. 我想这样做,所以有一个新的hint(问题),我可以用与第一个输入不同的方式操纵该输入。

In my example, my first EditText is enter_one and I want it to change to enter_two after the next_button is clicked. 在我的例子,我第一次的EditText是enter_one ,我希望它更改为enter_twonext_button被点击。

Thank you for your help! 谢谢您的帮助!

final EditText getInput = (EditText)findViewById(R.id.enter_key_one);
Button clickButton = (Button) findViewById(R.id.next_button);
clickButton.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View view) {
        String newValue = getInput.getText().toString().trim();
        int input = Integer.parseInt(newValue);
        System.out.println("Your value is " +input);
    }
});

Create two edit text in XML layout, and align both in same position, one over another. 在XML布局中创建两个编辑文本,然后将两个文本对齐在同一位置,彼此对齐。 Then declare the android:visibility="gone" for edittext enter_two . 然后将android:visibility="gone"为edittext enter_two

Then onClick of next should be: 然后onClick的next应该是:

final EditText getInput = (EditText)findViewById(R.id.enter_key_one);

final EditText getInput_two = (EditText)findViewById(R.id.enter_key_two);
Button clickButton = (Button) findViewById(R.id.next_button);
clickButton.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View view) {
        String newValue = getInput.getText().toString().trim();
        int input = Integer.parseInt(newValue);
        System.out.println("Your value is " +input);

getInput_two.setVisibility(View.VISIBLE);
getInput.setVisibility(View.GONE);

    }
});

You can just change the hint and clear the EditText : 您可以更改提示并清除EditText

final EditText getInput = (EditText)findViewById(R.id.enter_key_one);
Button clickButton = (Button) findViewById(R.id.next_button);
clickButton.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View view) {
        getInput.setHint(newQuestion);
        getInput.setText("");
    }
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM