2016-07-18 3 views
0

Я получаю неправильные значения из Listview после нажатия на него.Listview не дает правильных значений

Flow:

а) У меня есть Spinner Spinner раз выбирают значения ListView получает изменены с помощью в помощи AsyncTask.

OnPostMethod Метод AsyncTask для загрузки элементов в Listview

protected void onPostExecute(List<MIC_OrderDetails> lst) { 
      dialog.setMessage("Inflating Data..."); 

      if (lst.get(lst.size() - 1).getResult().contains(("success"))) { 

       ordList.addAll(lst); 
       ordList.notifyDataSetChanged(); 
       dialog.dismiss(); 

       /* 
       * ordList = new MicListAdapter(InventoryCount.this, lst); 
       * lstView.setAdapter(ordList); 
       * 
       * dialog.dismiss(); 
       */ 

      } else { 
       dialog.dismiss(); 
       toastText.setText("Problem in loading Items"); 
       Toast toast = new Toast(getApplicationContext()); 
       toast.setGravity(Gravity.CENTER_VERTICAL, 0, 410); 
       toast.setDuration(Toast.LENGTH_LONG); 
       toast.setView(toastLayout); 
       toast.show(); 
      } 
     } 

В Мой адаптер MicListAdapter я создал addAll() метод, так как прямой вызов не работает для меня

public void addAll(List<MIC_OrderDetails> lst) { 
     this.alllst.clear(); 
     this.alllst.addAll(lst); 
     this.notifyDataSetChanged(); 
    } 

б) OnClicking ListView Соответствующие значения не входят в поле «Пользовательский диалог», то есть

Предположим, что мой Spinner содержит два значения (1 & 2). По умолчанию в первый раз 1 будет отображаться в Spinner, когда я изменил его на 2, что влияет на значения Listview, которые соответствуют «2», но когда я нажал на Listview, значения, которые я получил, принадлежат «1 ».

Вот фрагмент кода для Listview OnClick

lstView.setOnItemClickListener(new OnItemClickListener() { 
    @Override 
        public void onItemClick(AdapterView<?> arg0, View arg1, 
          int position, long arg3) { 

MIC_OrderDetails list_obj = new MIC_OrderDetails(); 
        list_obj = (MIC_OrderDetails) lstView 
          .getItemAtPosition(position); 

        ItemNo = list_obj.getItemNumber(); 
        Desc = list_obj.getItemDescription(); 
        PickSeq = list_obj.getPickSeq(); 
        StockUnit = list_obj.getUnit(); 
        qtyonHand = list_obj.getQtyonHand();// This value gives 
                 // QOHand 
        qtyCount = list_obj.getQtyCount(); 
        loc = mspinner.getItemAtPosition(
          mspinner.getSelectedItemPosition()).toString(); 

        medtItem.setText(ItemNo); 
        medtdesc.setText(Desc); 

        qtyCount = supporter.getCurrencyFormat(Double 
          .parseDouble(qtyCount)); 

        medtQtyCount.setText(qtyCount); 
        medtuom.setText(StockUnit); 
        medtQtyCountTotal.setText(qtyCount); 
..... 
}); 

Это мой полный класс адаптера.

public class MicListAdapter extends ArrayAdapter<MIC_OrderDetails> implements 
    Filterable { 

List<MIC_OrderDetails> alllst; 
List<MIC_OrderDetails> list; 

List<MIC_OrderDetails> filterlst; 
// = new ArrayList<MIC_OrderDetails>(); 
Context context; 

TextView txtitem; 
TextView txtdesc; 
TextView txtpick; 
TextView txtQtyonHand; 
TextView txtQtyCounted; 
TextView txtuom; 
/* TextView txtstatus; */ 

private ModelFilter filter; 

@Override 
public Filter getFilter() { 
    if (filter == null) { 
     filter = new ModelFilter(); 
    } 
    return filter; 
} 

public MicListAdapter(Context context, List<MIC_OrderDetails> value) { 
    // TODO Auto-generated constructor stub 
    super(context, R.layout.six_textview, value); 
    this.context = context; 
    this.list = value; 
    this.alllst = new ArrayList<MIC_OrderDetails>(list); 
    this.filterlst = new ArrayList<MIC_OrderDetails>(alllst); 
    getFilter(); 
} 

public void addAll(List<MIC_OrderDetails> lst) { 
    this.alllst.clear(); 
    this.alllst.addAll(lst); 
    this.notifyDataSetChanged(); 
} 

@Override 
public int getCount() { 
    // TODO Auto-generated method stub 
    return alllst.size(); 
} 

@Override 
public View getView(int position, View convertView, ViewGroup parent) { 

    final int pos = position; 

    View view = null; 
    if (convertView == null) { 

     convertView = LayoutInflater.from(getContext()).inflate(
       R.layout.six_textview, parent, false); 

     txtitem = (TextView) convertView.findViewById(R.id.txt_fullItemNo); 
     txtdesc = (TextView) convertView.findViewById(R.id.txt_fullDesc); 
     txtpick = (TextView) convertView.findViewById(R.id.txt_fullLoc); 
     txtQtyonHand = (TextView) convertView 
       .findViewById(R.id.txt_fullord); 
     txtQtyCounted = (TextView) convertView 
       .findViewById(R.id.txt_fullrecqty); 
     txtuom = (TextView) convertView.findViewById(R.id.txt_fullUom); 
     convertView.setTag(new OrdersViewHolder(txtitem, txtdesc, txtpick, 
       txtQtyonHand, txtQtyCounted, txtuom)); 

    } else { 
     OrdersViewHolder viewHolder = (OrdersViewHolder) convertView 
       .getTag(); 
    } 

    OrdersViewHolder holder = (OrdersViewHolder) convertView.getTag(); 

    holder.txtitem.setText(alllst.get(position).getItemNumber()); 
    holder.txtdesc.setText(alllst.get(position).getItemDescription()); 
    holder.txtpick.setText(alllst.get(position).getPickSeq()); 
    holder.txtQtyonHand.setText((alllst.get(position).getQtyonHand())); 
    /* 
    * String o=(lst.get(position).getQtyShiped()).toString(); String 
    * u=lst.get(position).getUom(); 
    */ 
    holder.txtQtyCounted.setText((alllst.get(position).getQtyCount())); 
    holder.txtuom.setText(alllst.get(position).getUnit()); 
    /* holder.txtstatus.setText(alllst.get(position).getStatus()); */ 

    return convertView; 

} 

/** Holds child views for one row. */ 
static class OrdersViewHolder { 

    TextView txtitem; 
    TextView txtdesc; 
    TextView txtpick; 
    TextView txtQtyonHand; 
    TextView txtQtyCounted; 
    TextView txtuom; 

    /* TextView txtstatus; */ 

    public OrdersViewHolder(TextView txtitem, TextView txtdesc, 
      TextView txtpick, TextView txtQtyonHand, 
      TextView txtQtyCounted, TextView txtuom) { 
     // TODO Auto-generated constructor stub 
     this.txtitem = txtitem; 
     this.txtdesc = txtdesc; 
     this.txtpick = txtpick; 
     this.txtQtyonHand = txtQtyonHand; 
     this.txtQtyCounted = txtQtyCounted; 
     this.txtuom = txtuom; 
     /* this.txtstatus=txtstatus; */ 

    } 

Может кто-нибудь пожалуйста, скажи мне, почему этот сценарий происходит для меня ... Спасибо заранее

ответ

1

Вместо использования lstView использования arg0, который первый параметр onItemClick метода для получения щелкнуло значение элемента:

list_obj = (MIC_OrderDetails)arg0.getAdapter().getItem(position); 

ИЛИ

Использование объекта lst List:

list_obj = lst.get(position); 

Но нужно объявить lst как глобальную переменную для доступа к нему за пределами класса, расширяющее Asynctask

+0

Я попробовал то же самое, но она сохраняется такой же, как before.nothing изменилось. –

+0

@PraneshSahu: хорошо показать код адаптера –

+0

пожалуйста, проверьте мой обновленного MicListAdapter полного адаптера класса @ ρяσѕρую K –

Смежные вопросы