2016-07-14 9 views
0

私はチェックボックス付きリストビューを持っています。私は、EventHandlerクラスにリストビューを配置します。戻るボタンを押すとチェックボックスをすべてオフにしたい他のアクティビティでonBackPressedメソッドを呼び出します。だから私はビューを返すための別の関数を書く必要があります。助けてください。私はたくさん検索しましたが、正確な解決策を見つけることができませんでした。androidでonBackPressedのチェックボックスをすべてオフにしました

クラス内:チェックボックスのarraylistがチェックボックスをオフにします。

private ArrayList<ViewHolder> mViewHolders = new ArrayList<>(); 

ViewHolder:

private static class ViewHolder { 
    TextView topView; 
    TextView bottomView; 
    TextView dateView; 
    ImageView icon; 
    CheckBox checkBox; 
} 

getViewメソッド:

public View getView(int position, View convertView, ViewGroup parent) { 
    final ViewHolder mViewHolder; 
    int num_items = 0; 
    String temp = mFileMang.getCurrentDir(); 
    File file = new File(temp + "/" + mDataSource.get(position)); 
    String[] list = file.list(); 

    if(list != null) 
     num_items = list.length; 

    if(convertView == null) { 
     LayoutInflater inflater = (LayoutInflater) mContext. 
      getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
     convertView = inflater.inflate(R.layout.tablerow, parent, false); 

     mViewHolder = new ViewHolder(); 
     mViewHolder.topView =(TextView)convertView.findViewById(R.id.top_view); 
     mViewHolder.bottomView = (TextView)convertView.findViewById(R.id.bottom_view); 
     mViewHolder.dateView =(TextView) convertView.findViewById(R.id.date_view); 
     mViewHolder.icon = (ImageView)convertView.findViewById(R.id.row_image); 
     mViewHolder.checkBox = (CheckBox) convertView.findViewById(R.id.row_checkBox); 
     convertView.setTag(mViewHolder); 

     } else { 
      mViewHolder = (ViewHolder)convertView.getTag(); 

     } // I also make some text setting inside this. 
+1

アクティビティのコールバックをonBackPressed()、f ireコールバックメソッドは、アダプタでコールバックを実装し、コールバックメソッドの本体でチェックボックスをオフにします。 – EagleEye

+0

しかし、1つのチェックボックスを無効にしたい場合や、表示する場合のみ、またはすべてを無効にする場合も考慮してください。 –

+0

私はそれらのすべてをクリアしたい – gunescelil

答えて

2

をチェックonBackPressedその配列をロードすることができます。

+0

私は必要以上に感謝します。 – gunescelil

1

私はあなたが県にあるチェックボックスの値を格納するために

onbackpressチェックボックスの値を変更することをお勧め
アクティビティ:県の店舗ブール配列

public boolean storebaray(Boolean[] array, String arrayNam, Context mContext) { 

    SharedPreferences prefs = mContext.getSharedPreferences("prefname", 0); 
    SharedPreferences.Editor editor = prefs.edit(); 
    editor.putInt(arrayNam +"size", array.length); 

    for(int i=0;i<array.length;i++) 
     editor.putBoolean(arrayNam + "_" + i, array[i]); 

    return editor.commit(); 
} 

あなたは

public Boolean[] loadAry(String arrayNam, Context mContext) { 

    SharedPreferences prefs = mContext.getSharedPreferences("prefname", 0); 
    int size = prefs.getInt(arrayNam + "size", 0); 
    Boolean array[] = new Boolean[size]; 
    for(int i=0;i<size;i++) 
     array[i] = prefs.getBoolean(arrayNam + "_" + i, false); 

    return array; 
} 

、ワークフローは次のようにあるべき値に私のコメントを1として

関連する問題