so the question is, how can i make a buttonGenerator in android studio (with a unique Text, unique ID and unique name [for exanple unsig a for loop, to pass their names]). I have been tested some coding, but I've got always some errors (for example: where on the layer should the created Button appear, ...) and every time that the user clicks on the ButtonGenerator, the created button should appear underneath the last created button ( for example in a LinearLayout). I've tried it with visible and invisible, but i assume it is not the right way to do it. I have already a Button and everytime that the user clicks on that button, another Button will be created.
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//buttons
btnCreate= (ImageButton)findViewById(R.id.btnCreateID);
btnDelete= (ImageButton)findViewById(R.id.btnDeleteID);
btnCheck=(ImageButton)findViewById(R.id.btnCheckID);
getTime = (ImageButton) findViewById(R.id.getTimeID);
//Textviews
txt= (TextView)findViewById(R.id.txtID);
timeText= (TextView)findViewById(R.id.timeTextID);
//image
numImage = (ImageView)findViewById(R.id.numImageID);
//Edittexts
getTxt= (EditText)findViewById(R.id.getTxtID);
//change visibility
btnDelete.setVisibility(View.INVISIBLE);
getTime.setVisibility(View.INVISIBLE);
btnCheck.setVisibility(View.INVISIBLE);
txt.setVisibility(View.INVISIBLE);
timeText.setVisibility(View.INVISIBLE);
getTxt.setVisibility(View.INVISIBLE);
numImage.setVisibility(View.INVISIBLE);
btnCreateClick();
}
//hit Add
public void btnCreateClick() {
btnCreate.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
getTxt.setVisibility(View.VISIBLE);
getTime.setVisibility(View.VISIBLE);
btnCheck.setVisibility(View.VISIBLE);
btnCreate.setVisibility(View.INVISIBLE);
onGetTimeClick();
btnCheckClick();
btnDeleteClick();
}
});
}