Я понял. это не может быть правильным способом, но я так и сделал.
Я первый добавить привязок
@BindView(R.id.btnAddIngredient)
Button btnAdd;
@BindView(R.id.addNextBtn2)
Button btnNext;
@BindView(R.id.ingListLayout)
LinearLayout linearLayout;
Затем я добавил этот код
@OnClick({
R.id.btnAddIngredient,
R.id.addNextBtn2
})
public void onClick(Button button) {
switch (button.getId()) {
case R.id.btnAddIngredient:
qty = edtxt1.getText().toString();
measurement = edtxt2.getText().toString();
Ingredient = edtxt3.getText().toString();
inputString = qty+" "+measurement+" of "+Ingredient;
TextView ing = new TextView(this);
ing.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT));
ing.setText(inputString);
linearLayout.addView(ing);
edtxt1.setText(null);
edtxt2.setText(null);
edtxt3.setText(null);
break;
case R.id.addNextBtn2:
//What does this button do
if (jsonArray != null) {
Intent i = new Intent(AddRecipeScreen2.this, AddRecipeScreen3.class);
startActivity(i);
}else
Toast.makeText(mContext, "Please add Ingredients!",
Toast.LENGTH_LONG).show();
break;
}
}
показать код, пожалуйста. Что у вас есть? –
Мне нужно будет добавить код через несколько часов, когда я доберусь до своего ноутбука. Я пытался понять, как это сделать, прежде чем я вернусь домой. – Vahalaru