-1

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.

Vahalaru
  • 380
  • 4
  • 15

1 Answers1

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