2017-02-16 10 views
1

私はアンドロイドプログラムを持っていますが、リストビューが正しく動作しません。 リストビューにスクロールするアイテムがある場合は、最後のチェックボックスをクリックして別のアイテムのスクロールをスクロールします。私のコードsample.pleaseが私にこれを解決するのを助けてください。CheckBox付きリストビュースクロールの問題

アダプタクラスのgetViewのためのこの私のコード

@SuppressLint("InflateParams") 
    public View getView(int position, View convertView, ViewGroup parent) { 

     View vi = convertView; 
     if(convertView==null){ 
      vi = inflater.inflate(R.layout.unsettled_invoice_layout, null); 
      holder = new ViewHolder(); 
      holder.desc = (TextView) vi.findViewById(R.id.usinvoicedesc); 
      holder.chkbox = (CheckBox) vi.findViewById(R.id.selected); 
      holder.chkbox.setOnClickListener(new OnItemClickListener(position)); 
      vi.setTag(holder); 
      vi.setTag(R.id.selected, holder.chkbox); 
     } else 
      holder=(ViewHolder)vi.getTag(); 
     if(data.size()<=0){ 
      holder.desc.setText("No Data"); 
     }else{ 
      tempValues=null; 
      tempValues = (Invoice)data.get(position); 
      if(mode == 1){ 
       int myColor = Color.rgb(0, 128, 0); 
       if(tempValues.getStatus() == 2){ 
         myColor = Color.rgb(0, 128, 0);  // Green   
         holder.chkbox.setChecked(false); 
       }else if(tempValues.getStatus() == 3){ 
         myColor = Color.rgb(128, 0, 0); // Red 
         holder.chkbox.setChecked(true); 
       } 
       holder.desc.setBackgroundColor(myColor); 
      } 
      holder.desc.setText(tempValues.toString()); 
      vi.setOnClickListener(new OnItemClickListener(position)); 
     } 
     return vi; 
    } 

にこれは、私はあなたがHashMapを維持する必要がある。このためにアンドロイド

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:layout_gravity="top" 
    android:clickable="false" 
    android:descendantFocusability="blocksDescendants" 
    android:focusable="false" 
    android:focusableInTouchMode="false" 
    android:paddingTop="0dip" 
    android:textColor="#000000" > 

    <LinearLayout 
     android:id="@+id/usinvoicelayout" 
     android:layout_width="fill_parent" 
     android:layout_height="95dp" 
     android:layout_marginBottom="3dp" 
     android:layout_marginTop="2dip" 
     android:clickable="false" 
     android:descendantFocusability="blocksDescendants" 
     android:focusable="false" 
     android:focusableInTouchMode="false" 
     android:orientation="horizontal" 
     android:paddingTop="0dip" > 

     <TextView 
      android:id="@+id/usinvoicedesc" 
      android:layout_width="520dp" 
      android:layout_height="90dp" 
      android:layout_gravity="start" 
      android:gravity="center_vertical" 
      android:textColor="#FFFF00" 
      android:textSize="18sp" /> 

     <CheckBox 
      android:id="@+id/selected" 
      android:layout_width="50dp" 
      android:layout_height="80dp" 
      android:layout_marginStart="15dip" 
      android:button="@drawable/checkbox_background" 
      android:clickable="false" 
      android:focusable="false" 
      android:focusableInTouchMode="false" /> 
    </LinearLayout> 

</LinearLayout> 
+2

あなたの問題にはたくさんの質問と解決策があると思います。お試しください –

答えて

0

に使用layout.xmlです。チェックボックスをオンにすると、ハッシュマップの位置を設定し、設定前にgetviewでチェックボックスをオンにすると、ハッシュマップの位置がチェックされます。存在する場合は、チェックボックスをオンにします。

0

リンクの下に確認してください: それは、スクロールで確認他の項目のチェックボックスのあなたの問題のための具体的な解決策である:上記のリンクの例では

http://lalit3686.blogspot.in/2012/06/today-i-am-going-to-show-how-to-deal.html

をあなたのリストビューのアダプタクラスgetViewメソッド()メソッド内のコードの下に追加:

viewHolder.checkbox.setTag(position); // This line is important. 

と、チェックボックスをクリックするためのコードの下に追加します。

viewHolder.checkbox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { 

       @Override 
       public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { 
        int getPosition = (Integer) buttonView.getTag(); // Here we get the position that we have set for the checkbox using setTag. 
        list.get(getPosition).setSelected(buttonView.isChecked()); // Set the value of checkbox to maintain its state. 
       } 
      }); 

あなたの問題の解決に役立つ場合は、回答を受け入れてください。

+0

まだ私の問題は解決していません –

関連する問題