2012-03-01 12 views
0

私はこの昨日この質問をしましたが、私はこの問題がはるかに複雑であると書きました。私は非常に混乱しており、ここでは非常によく似た質問がありますが、どちらも私の問題を解決しませんでした。だから、私はリストビューを持っている、すべてのリストビューは、テキストビューとedittextが含まれていますが、edittextだけが重要です。 私がtextviewをクリックすると、テストのためにその内容を記録したいと思います。私の問題は、ユーザーが変更した後、同じことをログに記録した後です。エミュレータでsetTextを使わずに変更すると、何もしません。私はデータベースを持っている、リストビューのすべてにedittext(holder.quant)がある。私はそれを変更した場合、編集内容は更新されません

クラスMyAdapterはArrayAdapter {

LayoutInflater inflat; 
    ViewHolder holder; 
    public MyAdapter(Context context, int textViewResourceId, 
      ArrayList<EachRow> objects) 
    { 

     super(context, textViewResourceId, objects); 
     // TODO Auto-generated constructor stub 
     inflat=LayoutInflater.from(context); 
    } 
    @Override 
    public View getView(int position, View convertView, ViewGroup parent) { 
     // TODO Auto-generated method stub 

     if(convertView==null) 
     { 
      convertView=inflat.inflate(R.layout.row_checkox, null); 
      holder=new ViewHolder(); 
      holder.textView=(TextView)convertView.findViewById(R.id.textView111); 
      holder.image=(ImageView)convertView.findViewById(R.id.imageView111); 



      holder.quant = (EditText)convertView.findViewById(R.id.quantity); 


      holder.image.setOnClickListener(CustomList.this); 
      convertView.setTag(holder); 
     } 
     holder=(ViewHolder) convertView.getTag(); 



     holder.textView.setOnClickListener(new View.OnClickListener() { 


      @Override 
      public void onClick(View v) { 

       TextView tv = (TextView) v ; 
      String text_of_clicked_textview = tv.getText().toString(); 

      final String[] ddata = text_of_clicked_textview.split(" "); //split the result using the spaces (so you could obtain the name, hotness and the other string you use) 


       final long yy = Long.parseLong(ddata[0]); 



       info.open(); 
       info.updateQuan(yy, holder.quant.getText().toString()); 
       Log.i("tagitagi", holder.quant.getText().toString()); 
       info.close(); 
      } 
     }); 



     EachRow row= getItem(position); 
     EachRow row2= getItem2(position); 
     holder.quant.setText(row2.text); 

     holder.textView.setText(row.text); 
     NullPointerException 
     holder.image.setTag(position); 
     holder.quant.setTag(position); 

     return convertView; 
    } 

    @Override 
    public EachRow getItem(int position) { 
     // TODO Auto-generated method stub 
     return list.get(position); 
    } 
    public EachRow getItem2(int position) { 
     // TODO Auto-generated method stub 
     return list2.get(position); 
    } 

    private class ViewHolder 
    { 
     TextView textView; 
     ImageView image; 
     EditText quant; 


    } 
} 

private class EachRow 
{ 
    String text; 
    boolean checkBool; 
} 

を拡張し、私はaddTextChangedListenerを試してみましたが、私はのsetTextを使用する場合、それは私にエラーを与えます。それで問題は何ですか?

ありがとうございます!

答えて

0

私はそれをどのように機能させることができるか把握することができました。 holder.quant.gettext()。toStringは動作しません。たとえテキストビューをクリックしても、テキストビューの内容をログできません。

だから私は、新しいメソッドを作成するために必要なホルダー何とかブロックそれは、私がいつも同じのTextViewをログに記録します...:

public String getTextOfSelectedRow(int position) { 
         return list.get(position).text; 
     } 

をリストに行が含まれている、の.textは方法から来ています:

private class EachRow 
    { 
     String text; 
     boolean checkBool; 
    } 

とホルダーの定義:

public View getView(final int position, View convertView, ViewGroup parent) { 
      // TODO Auto-generated method stub 

      if(convertView==null) 
      { 
       convertView=inflat.inflate(R.layout.row_checkox, null); 
       holder=new ViewHolder(); 
       holder.textView=(TextView)convertView.findViewById(R.id.textView111); 
       holder.image=(ImageView)convertView.findViewById(R.id.imageView111); 

       holder.quant = (EditText)convertView.findViewById(R.id.quantity); 
      holder.button = (Button)convertView.findViewById(R.id.dialogQuan); 
       holder.image.setOnClickListener(CustomList.this); 
       convertView.setTag(holder); 
      } 
      holder=(ViewHolder) convertView.getTag(); 



      holder.button.setOnClickListener(new View.OnClickListener() {.... 

ので、この後のonClickメソッド:

kmultip = getTextOfSelectedRow(position).toString(); 

これで私はholder.quantまたはholder.textviewなどの行を参照できます。私はまだ単純なholder.quant.getText()。toStringが動作しない理由を知りませんが、これにより、行の位置を参照すると動作するようになります。

0

私はこれをまっすぐにしましょう。 TextViewをクリックすると、EditTextの内容を記録しますか?

なぜのTextViewでリスナーののonClickメソッドで呼び出すだけではない:

Log.d("EditText Content", holder.quant.getText().toString()); 

をあなたは単にEDITTEXTの内容をつかむためOnTextChangeListenerは必要ありません。

+0

Ajcodez、これはここで起こっていることですが、私はあなたを理解していません。最後の行にある –

+0

問題は、エミュレータのコンテンツを変更して同じデータを取得したときにログに記録されます。 –

+0

ああ、EditTextのテキストを変更してログに記録すると、同じ結果になります。おそらくあなたの所有者に問題がありますか? – AJcodez

0

最初に、新しいビューである場合にのみコンテンツを表示します。これは、すべてのリストコンテンツを静的にする場合にのみ機能します。本気ですか?

秒 - あなたはArrayAdapterの機能を使用していません。 Look here

関連する問題