2012-08-08 63 views
0

在我的android應用程序中,我使用分頁顯示使用listview的所有產品。在listview裏面有一個checkBox和一個imageview。我使用checkBox從列表視圖中選擇特定的圖像。我從服務器獲取所有圖像。首先,我將所有圖像放在ArryList中,然後我在android臨時ArrayList中使用5個元素,並使用臨時的自定義數組適配器並加載該5個圖像。問題是,當我選擇一個複選框來選擇特定的圖像,然後單擊下一個按鈕,然後在新的頁面內我得到另一個選中的複選框。除此之外,我在每個頁面中都會看到一個選定的按鈕。如何刪除這個?我希望複選框在Checked的位置點擊。我的代碼如下。安卓複選框意外在列表視圖中檢查

private class MyCustomAdapter extends ArrayAdapter<WatchListAllEntity> { 

    private static final int TYPE_ITEM = 0; 
    private static final int TYPE_ITEM_WITH_HEADER = 1; 
    private ArrayList<WatchListAllEntity> mData = new ArrayList(); 
    private LayoutInflater mInflater; 
    private ArrayList<WatchListAllEntity> items = new ArrayList<WatchListAllEntity>(); 

    public MyCustomAdapter(Context context, int textViewResourceId, 
      ArrayList<WatchListAllEntity> items) { 
     super(context, textViewResourceId, items); 
     this.items = items; 
    } 

    public void addItem(WatchListAllEntity watchListAllEntity) { 

     items.add(watchListAllEntity); 
    } 

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

     View v = convertView; 
     final int position1 = position; 
     if (v == null) { 

      LayoutInflater vi = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
      v = vi.inflate(R.layout.listitempict, null); 
     } 
     watchListAllEntity = new WatchListAllEntity(); 
     watchListAllEntity = items.get(position); 
     Log.i("position: iteamsLength ", position + ", " + items.size()); 
     if (watchListAllEntity != null) { 

      ImageView itemImage = (ImageView) v 
        .findViewById(R.id.imageviewproduct); 

      if (watchListAllEntity.get_thumbnail_image_url1() != null) { 

       Drawable image = Utility.ImageOperations(watchListAllEntity.get_thumbnail_image_url1().replace(" ", "%20"),"image.jpg"); 



       if (image != null) { 
        itemImage.setImageDrawable(image); 
        itemImage.setAdjustViewBounds(true); 
       } else { 

        itemImage.setImageResource(R.drawable.iconnamecard); 
       } 

       Log.i("status_ja , status", 
         watchListAllEntity.get_status_ja() + " ," 
           + watchListAllEntity.getStatus()); 

       int NewtheStatus = Integer.parseInt(watchListAllEntity 
         .getStatus()); 
       CheckBox checkBox = (CheckBox) v 
         .findViewById(R.id.checkboxproduct); 
       TextView alreadyOrderText = (TextView) v 
         .findViewById(R.id.alreadyordertext); 
       if (NewtheStatus == 1) { 
        alreadyOrderText.setVisibility(4); 

        checkBox.setVisibility(0); 
       } else { 
        checkBox.setVisibility(4); 
        alreadyOrderText.setVisibility(0); 
       } 
       Log.i("Loading ProccardId: ", 
         watchListAllEntity.get_proc_card_id() + ""); 
       checkBox.setOnCheckedChangeListener(new OnCheckedChangeListener() { 

        public void onCheckedChanged(CompoundButton buttonView, 
          boolean isChecked) { 
         WatchListAllEntity watchListAllEntity2 = items 
           .get(position1); 
         Log.i("Position: ", position1 + ""); 

         if (isChecked) { 

          Constants.orderList.add(watchListAllEntity2 
            .get_proc_card_id()); 
          Log.i("Proc Card Id Add: ", 
            watchListAllEntity2.get_proc_card_id() 
              + ""); 


         } else { 
          Constants.orderList.remove(watchListAllEntity2 
            .get_proc_card_id()); 
          Log.i("Proc Card Id Remove: ", 
            watchListAllEntity2.get_proc_card_id() 
              + ""); 

         } 

        } 
       }); 
      } 

     } 

     return v; 
    } 
+0

http://www.lalit3686.blogspot.in/2012/06/today-i-am-going-to-show-how-to-deal.html – 2012-08-08 08:07:38

+0

14個問題沒有接受? – cjk 2012-08-08 08:17:03

回答

0

如果它包含android:checked =「true」語句,請檢查newpage.xml文件中的CheckBox元素。