0

У меня есть список, содержащий некоторые значения. Мне нужно создать диалог в виде списка на клике элемента. моя проблема заключается в том, что при нажатии любых элементов в диалоговом окне просмотра списка отображается количество элементов в виде списка. Мне просто нужен только один диалог для каждого элемента, который показывает соответствующие данные элемента.Диалоговое окно оповещений внутри элемента списка списка прослушивания

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

Вам не нужно использовать для цикла. Вы получаете нажатый элемент как 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

hey it works..but Почему я не могу ввести значение для редактирования текста? Мне нужно обновить одно из моих представлений в списке с помощью текстового значения редактирования. пожалуйста, знаешь почему? – Bivin

0

Попробуйте

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

Надежда! Это поможет вам

0

Не используйте для петли внутри onItemЩелкните. remove for loop, и вы можете получить объект просмотра из параметров метода.

parent.getItemAtPosition(position)); 
Смежные вопросы