I have an activity where the user enters some ingredient info and an add button. How would I add a textview using butterknife? I am currently getting no errors and nothing onscreen so I must be trying to implement this wrong.
Asked
Active
Viewed 577 times
-1
-
2show some code, please. What do you have so far? – Tyler Sebastian Feb 07 '17 at 23:23
-
I will have to add code in a few hours when I get to my laptop. I was trying to see the proper way to impliment this before I got home. – Vahalaru Feb 08 '17 at 00:28
1 Answers
0
I figured it out. this may not be the right way to do it but this is how I accomplished it.
I first add the binds
@BindView(R.id.btnAddIngredient)
Button btnAdd;
@BindView(R.id.addNextBtn2)
Button btnNext;
@BindView(R.id.ingListLayout)
LinearLayout linearLayout;
Then I added this code
@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
- 380
- 4
- 15