2017-02-07 5 views
-1

사용자가 일부 성분 정보와 추가 버튼을 입력하는 활동이 있습니다. 버터 나이프를 사용하여 텍스트 뷰를 추가하려면 어떻게해야합니까? 나는이 오류를 구현하려고 노력해야하므로 현재 오류가없고 화면에 아무것도 표시되지 않습니다.Android Butterknife add Textview onClick

+2

을 추가 한 바인딩 그리고

@BindView(R.id.btnAddIngredient) Button btnAdd; @BindView(R.id.addNextBtn2) Button btnNext; @BindView(R.id.ingListLayout) LinearLayout linearLayout; 

를하시기 바랍니다 추가 할 수 있습니다. 지금까지 뭐라구? –

+0

내 노트북에 도착하면 몇 시간 안에 코드를 추가해야합니다. 내가 집에 오기 전에 나는 이것을 함양 할 적절한 방법을 보려고 노력했다. – Vahalaru

답변

0

알아 냈습니다. 이것이 올바른 방법이 아닐지 모르지만 이것이 내가 성취 한 방법입니다.

내가 먼저 몇 가지 코드를 보여이 코드

@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; 

     } 
    }