0

私はいくつかの値を含むリストビューを持っています。私はリストビューの項目をクリックしてダイアログを生成する必要があります。私の問題は、リストビューの項目のいずれかをクリックすると、リストビューの項目の数と同じに見えます。私はちょうど各アイテムクリックに1つのダイアログを必要とし、それは対応するアイテムの詳細を示します。リストアイテム内のアラートダイアログクリックリスナー

public void onItemClick(AdapterView<?> parent, View view, int position, 
     long id) { 
    // TODO Auto-generated method stub 


    float due = (float) 0.0; 
if(list != null){ 
     for(int i = 0; i< list.getChildCount();i++){ 
      View vie = list.getChildAt(i); 

     TextView amt = (TextView) vie.findViewById(R.id.amt); 
     TextView alloc = (TextView) vie.findViewById(R.id.alloc); 
     EditText ed = (EditText) vie.findViewById(R.id.edit); 
     String amnt = amt.getText().toString(); 
     String allc = alloc.getText().toString(); 



     // due amount is net amount minus allocation amount 
     due = Float.valueOf(amnt) - Float.valueOf(allc); 


     AlertDialog.Builder alertDial = new AlertDialog.Builder(Collection.this); 
     LayoutInflater inflater=Collection.this.getLayoutInflater(); 
     //this is what I did to added the layout to the alert dialog 
     View layout=inflater.inflate(R.layout.alert_layout,null);  
     alertDial.setView(layout); 
     final TextView dues=(TextView)layout.findViewById(R.id.textViewdue); 
     final EditText received=(EditText)layout.findViewById(R.id.rcvd); 
     dues.setText("Float.toString(due)"); 
     AlertDialog alertDialog = alertDial.create(); 

      // show alert 

      alertDialog.show(); 
    } 
} 
} 

また、ダイアログ内の編集テキストに値を入力できませんでした。私を助けてください。

答えて

0

forループを使う必要はありません。クリックしたアイテムはView viewとなります。次のコードを試してください

public void onItemClick(AdapterView<?> parent, View view, int position, 
     long id) { 
    // TODO Auto-generated method stub 


    float due = (float) 0.0; 
if(list != null){ 


     TextView amt = (TextView) view.findViewById(R.id.amt); 
     TextView alloc = (TextView) view.findViewById(R.id.alloc); 
     EditText ed = (EditText) view.findViewById(R.id.edit); 
     String amnt = amt.getText().toString(); 
     String allc = alloc.getText().toString(); 



     // due amount is net amount minus allocation amount 
     due = Float.valueOf(amnt) - Float.valueOf(allc); 


     AlertDialog.Builder alertDial = new AlertDialog.Builder(Collection.this); 
     LayoutInflater inflater=Collection.this.getLayoutInflater(); 
     //this is what I did to added the layout to the alert dialog 
     View layout=inflater.inflate(R.layout.alert_layout,null);  
     alertDial.setView(layout); 
     final TextView dues=(TextView)layout.findViewById(R.id.textViewdue); 
     final EditText received=(EditText)layout.findViewById(R.id.rcvd); 
     dues.setText("Float.toString(due)"); 
     AlertDialog alertDialog = alertDial.create(); 

      // show alert 

      alertDialog.show(); 
    } 
} 
+0

私はテキストを編集するために値を入力できませんでした。私はリスト内の私のビューの1つを編集テキスト値で更新する必要があります。あなたはなぜ知っていますか? – Bivin

0

この

if(posstion==0){ 
//showYourDialog have value 0 
}else if(posstion==1){ 
//showYourDilog have value 1 
} 

希望をお試しください!助けてください

0

forループ内のforItemClickを使用しないでください。 remove forループを実行すると、メソッド・パラメーターからビュー・オブジェクトを取得できます。

parent.getItemAtPosition(position)); 
関連する問題