Hey android hackers, I need some help with a game I'm making. I'm just trying to learn android programming and improve my java skills, so it's not going to be anything big.
To begin with there should be a screen (Activity) that lets the user decide how many players there will be. It should do this by having one text field and a button to begin with, and when the button (labeled "Add Player") is pressed there should be a new text field in between the old text field and the button. It should be possible to do this indefinitely (well, until the memory runs out).
I don't care if this is a bad UI decision. It was the first idea I had in mind and now that I got this problem, I want to understand how to solve it. When I've solved it I want to hear about other UI ideas for this.
I have written the XML file and there is one text field and one button to begin with, just as intended. The problem comes when I press the button and it should add a new text field. I just can't figure out how to do this.
tl;dr: I want a new text field to appear when I click a button. How?
[...]
public class HurrDurr extends Activity {
private ArrayList<Player> players;
private Button button;
private int defaultView;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
defaultView = R.layout.main;
setContentView(defaultView);
button = (Button) findViewById(R.id.more_players);
button.setOnClickListener(morePlayersListener);
}
private OnClickListener morePlayersListener = new OnClickListener() {
public void onClick(View v) {
//how do I add a text field from here?
}
};
}
//I believe this is all I need to post. If you want to see other files, tell me.
To begin with there should be a screen (Activity) that lets the user decide how many players there will be. It should do this by having one text field and a button to begin with, and when the button (labeled "Add Player") is pressed there should be a new text field in between the old text field and the button. It should be possible to do this indefinitely (well, until the memory runs out).
I don't care if this is a bad UI decision. It was the first idea I had in mind and now that I got this problem, I want to understand how to solve it. When I've solved it I want to hear about other UI ideas for this.
I have written the XML file and there is one text field and one button to begin with, just as intended. The problem comes when I press the button and it should add a new text field. I just can't figure out how to do this.
tl;dr: I want a new text field to appear when I click a button. How?
[...]
public class HurrDurr extends Activity {
private ArrayList<Player> players;
private Button button;
private int defaultView;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
defaultView = R.layout.main;
setContentView(defaultView);
button = (Button) findViewById(R.id.more_players);
button.setOnClickListener(morePlayersListener);
}
private OnClickListener morePlayersListener = new OnClickListener() {
public void onClick(View v) {
//how do I add a text field from here?
}
};
}
//I believe this is all I need to post. If you want to see other files, tell me.

