0

Ich habe eine Listenansicht mit einigen Werten. Ich brauche einen Dialog in der Listenansicht beim Klicken auf den Gegenstand. Mein Problem ist, wenn das Klicken auf ein Element im Listenansichtsdialog gleich der Anzahl der Elemente in der Listenansicht erscheint. Ich möchte nur einen Dialog für jeden Artikel klicken, der die entsprechenden Artikeldetails anzeigt.Alarmdialog im Listenelement Klick Listener

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(); 
    } 
} 
} 

Und auch kann ich nicht Werte in bearbeiten Text in Dialog eingeben. Bitte hilf mir.

Antwort

0

Sie müssen keine for-Schleife verwenden. Sie erhalten Artikel als View view angeklickt. Versuchen Sie folgenden Code

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

hey es funktioniert..aber warum konnte ich keinen Wert eingeben, um Text zu bearbeiten? Ich muss eine meiner Ansichten in der Liste mit dem Text bearbeiten Wert aktualisieren. Bitte weißt du warum? – Bivin

0

Versuchen Sie, diese

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

Hoffnung! Es hilft Ihnen

0

Verwenden Sie nicht für Schleife innerhalb OnItemClick. remove for loop und Sie können das Ansichtsobjekt aus den Methodenparametern abrufen.

parent.getItemAtPosition(position)); 
Verwandte Themen