• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps I have a problem that I have been stuck on for a while

What I am trying to do is get user input as a editText and output it to that amount so if the user enters 9 it outputs 9 textbox

here is the code:
questionAndTimer class:
public void onClick(View view) {
//Create Intent object which moves from QuestionAndTimer class
//to SendQuestion class
Intent intObj = new Intent(QuestionAndTimer.this, SendQuestion.class);
//Set the user entered question in value name which will be
//used in GreetingActivity class

intObj.putExtra("HOW", name2);

//Start sendQuestion
startActivity(intObj);

if (howManyQuestions != null && howManyQuestions.getText().length() != 0) {//check if user enters a numeric attribute
name2 = howManyQuestions.getText().toString();

}
else if(howManyQuestions.getText().toString().isEmpty()) {//check if user doesn't enter a numeric attribute
Toast.makeText(this, "please enter how many answers you are looking for..", Toast.LENGTH_SHORT).show();
return ;

}

sendQuestion class:

String howMany = (String) intename.getSerializableExtra("HOW");
if(howMany == "9") {

answers.setText("" + howMany);
answers.setText("" + howMany);
answers.setText("" + howMany);
answers.setText("" + howMany);
answers.setText("" + howMany);
answers.setText("" + howMany);
answers.setText("" + howMany);
answers.setText("" + howMany);
answers.setText("" + howMany);
}
 
If this is the same question as you asked last time, have you had a look at the links I posted on how to dynamically add components to your view?

In an app, the normal situation is to have your screen layout statically defined in the layout XML file.
If you wish to add or remove views e.g. EditText while the application is running, then you need to understand how to add Views to an existing ViewGroup. You can get many useful links and examples on how to do this by Googling "android dynamically add view" or similar words.

I've just noticed something else in your code. This will never do what you expect

Code:
String howMany = (String) intename.getSerializableExtra("HOW");
if(howMany == "9") {

The 'if' statement condition 'howMany == "9"' will always evaluate to false because you are using object comparison. It's a common gotcha in Java that catches out many beginners.
To compare two Strings for equivalence, what you need to do is use

Code:
if (howMany.equals("9")


But let's get back to your problem. In your SendQuestion class, have you tried to dynamically add an EditText view to the main view? What code did you write for that? Were there any specific problems you had?
 
Last edited by a moderator:
Back
Top Bottom