Reputation: 309
I have developed a program, but i need the interface to change, depending on user input.
Right now, i have made something like a numberpicker, with + and - buttons, but the problem is, some users will need to put in decimals. For that, i want to change the number-pickers out with a simple textbox
I want the program to be able to change back and forth between the 2 screens shown here, at the click of a button, without using different activities or xml files. everything but the number the user picks, are the same. If the stuff under the textbox doesnt stay at the same place but jumps up, (becouse the textfield fills less) thats okay.
How would you suggest doing this?
Upvotes: 0
Views: 121
Reputation: 54322
You have to play around with the visibility of your views. Add both number picker and EditText to the same layout and within the button click listener toggle between the visibility of them, like,
button.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
if(nNumberPicker.getVisibility()==View.VISIBLE)
{
nNumberPicker.setVisibility(View.GONE);
editText.setVisibility(View.VISIBLE);
}
else
{
nNumberPicker.setVisibility(View.VISIBLE);
editText.setVisibility(View.GONE);
}
}
});
And similarly change the visibility based on your need.
Upvotes: 1
Reputation: 479
Here an example
Button plus1 = (Button)findViewById(R.id.plus1); plus1.setVisibility(View.INVISIBLE); //invisible, but still takes up layout space //or plus1.setVisibility(View.GONE); //invisible, and doesn't takes up layout space //or plus1.setVisibility(View.VISIBLE); //visible
Upvotes: 1