2017-07-08 14 views
0

editBoxのレイアウトを動的に追加しました。editBoxから取得する値に対して計算を実行できるように、それぞれのeditBoxにtextListenerを設定します。私はレイアウトを膨らませるために以下のコードを使用しています。レイアウトを拡張するために使用しているViewオブジェクトにカウンタを設定することは可能ですか?どんなアイディアも大歓迎です。androidのeditTextsを動的に生成するtextListenerを設定する方法

public void addField1(View v) { 
      LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
      final View rowView = inflater.inflate(R.layout.field, null); 
      parentLinearLayout.addView(rowView, parentLinearLayout.getChildCount() - 1); 
      } 
    int count1 = parentLinearLayout.getChildCount(); 
       for (int n = 0; n < count1; n++) { 
        LinearLayout linearLayout = (LinearLayout) parentLinearLayout.getChildAt(n); 
     editValues3 = (EditText) linearLayout.getChildAt(3); 
     editValues3.addTextChangedListener(new TextWatcher() { 
         @Override 
         public void beforeTextChanged(CharSequence s, int start, int count, int after) { 
          Log.e("inside", "before" + s); 

         } 
         @Override 
         public void onTextChanged(CharSequence s, int start, int before, int count) { 
          Log.e("inside", "on text" + s); 
         } 
         @Override 
         public void afterTextChanged(Editable s) { 
          Log.e("inside", "afterText" + s); 
          if(editValues3.getText().length()>0){ 
           valCalculations(); 
          } 
         } 
        }); 
       } 
+0

あなたが直面している問題は何ですか? – earthw0rmjim

+0

あなたのコードは上手く見えますが、何が問題なのですか? –

+0

リスナーは1つの編集テキストボックスに追加されています –

答えて

-1

は、私はあなたがaddTextChangedListenerを実装し、そのカスタムクラス内の適切な計算を行い、あなたのCustomEditTextを作成するべきだと思います。

+0

意味がない –

関連する問題