2013-09-30 36 views
0

我有一個Listview,其中包含一個微調器。我正在使用baseadapter類來填充列表視圖和微調框。我如何將我有的向量傳遞給ListView中的每個微調器。微調控制器的矢量與列表視圖中的所有項目相同。如何傳遞和更新數據到Baseadapter中的Baseadapter

工作流是列表視圖開始空,但對於微調的載體填充,不會改變。然後用戶將圖像添加到列表視圖中,並可能從微調控制器適配器中進行選擇。

我遇到的問題是微調似乎從來沒有得到數據,它甫一名單「請選擇」,每次我專注於微調時間就增加了兩個「請選擇」給它。

我還需要知道如何讓正在使用的兩個適配器從活動離心器的選擇的價值。

這裏是BaseadapterListview

public class InvoicePicAdapter extends BaseAdapter { 

private Context context; 
private ArrayList<InvoicePicItem> invoicepics; 
private VectorItemsOnInvoice itemsOnInvoice; 

public InvoicePicAdapter(Context context, ArrayList<InvoicePicItem> invoicepics,VectorItemsOnInvoice items){ 
    this.context=context; 
    this.invoicepics=invoicepics; 
    this.itemsOnInvoice=items; 
} 

@Override 
public int getCount() { 
    return invoicepics.size(); 
} 

@Override 
public InvoicePicItem getItem(int position) { 
    return invoicepics.get(position); 
} 

@Override 
public long getItemId(int position) { 
    return position; 
} 

protected void deleteImage(int position) { 
    this.invoicepics.remove(position); 
} 

@Override 
public View getView(final int position, View convertView, ViewGroup parent) { 
    if (convertView == null) { 
     LayoutInflater inflater = (LayoutInflater) context 
       .getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
     convertView = (View) inflater.inflate(
       R.layout.listview_item_invoice_pic, null); 
    } 

    ImageView imgPartPic=(ImageView)convertView.findViewById(R.id.imgPart); 

    imgPartPic.setTag(Integer.valueOf(position)); 
    imgPartPic.setOnLongClickListener(new View.OnLongClickListener() { 
     @Override 
     public boolean onLongClick(final View v) { 
      AlertDialog.Builder builder = new AlertDialog.Builder(context); 
      builder.setMessage("Delete this Picture?"); 
      builder.setCancelable(true); 
      builder.setPositiveButton("Yes", 
        new DialogInterface.OnClickListener() { 
       public void onClick(DialogInterface dialog, int id) { 
        int position = (Integer) v.getTag(); 
        deleteImage(position); 
        notifyDataSetChanged(); 
        dialog.cancel(); 
       } 
      }); 
      builder.setNegativeButton("No", 
        new DialogInterface.OnClickListener() { 
       public void onClick(DialogInterface dialog, int id) { 
        dialog.cancel(); 
       } 
      }); 

      AlertDialog alert = builder.create(); 
      alert.show(); 

      return true; 
      } 
     }); 

    android.view.ViewGroup.LayoutParams layoutParams = imgPartPic.getLayoutParams(); 
    layoutParams.width = 400; 
    layoutParams.height = 300; 
    imgPartPic.setLayoutParams(layoutParams); 
    imgPartPic.setScaleType(ScaleType.FIT_XY); 

    imgPartPic.setImageBitmap(invoicepics.get(position).getImage()); 

    Spinner spinItemsOnInvoice = (Spinner)convertView.findViewById(R.id.spinnerItemsOnInvoice); 
    InvoicePicSpinAdapter spinnerAdapter = new InvoicePicSpinAdapter(context, 
      android.R.layout.simple_spinner_item,itemsOnInvoice); 
    spinItemsOnInvoice.setAdapter(spinnerAdapter); 
    return convertView; 
} 
} 

然後這是Spinner BaseAdapter的代碼。

public class InvoicePicSpinAdapter extends ArrayAdapter<ItemsOnInvoice>{ 
private VectorItemsOnInvoice values; 
private Context context; 

public InvoicePicSpinAdapter(Context context, int simpleSpinnerItem, 
     VectorItemsOnInvoice response) { 
    super(context, simpleSpinnerItem, response); 
    ItemsOnInvoice pleaseSelect = new ItemsOnInvoice(); 
    pleaseSelect.inventoryID=0; 
    response.add(0, pleaseSelect); 
    this.values= response; 
    this.context = context; 
} 

public void updateItemsOnInvoice(VectorItemsOnInvoice items){ 
    ItemsOnInvoice pleaseSelect = new ItemsOnInvoice(); 
    pleaseSelect.inventoryID=0; 
    items.add(0, pleaseSelect); 
    this.values= items; 
} 

public int getCount(){ 
    return values.size(); 
} 

public ItemsOnInvoice getItem(int position){ 
    return values.elementAt(position); 
} 

public long getItemId(int position){ 
    return position; 
} 

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

    TextView label = new TextView(context); 
    label.setTextColor(Color.BLACK); 

    if (values.elementAt(position).inventoryID==0){ 
     label.setText("Please Select"); 
    } else { 
     if (values.elementAt(position).isSPIG==0){ 
      label.setText("G"+String.valueOf(values.elementAt(position).groupNumber)); 
     } else { 
      label.setText("R"+String.valueOf(values.elementAt(position).inventoryID)); 
     } 
    } 
    return label; 
} 

@Override 
public View getDropDownView(int position, View convertView, 
     ViewGroup parent) { 
    TextView label = new TextView(context); 

    if (position==0){ 
     label.setTextColor(Color.GRAY); 
     label.setTextSize(22); 
     label.setText("Please Select"); 
    } else { 
     label.setTextColor(Color.BLACK); 
     label.setTextSize(28); 
     if (values.elementAt(position).inventoryID==0){ 
      label.setText("Please Select"); 
     } else { 
      if (values.elementAt(position).isSPIG==0){ 
       label.setText("G"+String.valueOf(values.elementAt(position).groupNumber)); 
      } else { 
       label.setText("R"+String.valueOf(values.elementAt(position).inventoryID)); 
      } 
     } 
    }  
    return label; 
} 
} 

回答

0

更新內容時是否在適配器上調用notifyDataSetChanged()?

+0

我的列表視圖DataAdapter的事,但我不知道怎麼說也是在適配器,但數據永遠不會改變,所以我不知道是否在適配器上我需要。 – pamsauto

0

第二個適配器上的返回值無效,每加載到屏幕上的每個新視圖組都會調用adapter-> getview()方法,即操作系統「知道」如何回收視圖以獲取更多信息,請參閱here視頻81-87應解釋整個主題相當不錯