これを処理するための完全なアダプター クラスを次に示します。
私はそのためにtoogleボタンを使用しています。チェックボックスでも同じことができます。チェックボックスの状態を維持する必要があります
public class SettingsListAdapter extends BaseAdapter implements
{
private LayoutInflater mInflater;
private DealsSTRUC[] setings_Adapt_Catagories;
Context mContext;
String isNotificationEnnabled;
public SettingsListAdapter( Context context, DealsSTRUC[] catagories ,String isEnnabled)
{
mContext = context;
setings_Adapt_Catagories = catagories;
mInflater = LayoutInflater.from(context);
isNotificationEnnabled=isEnnabled;
}
@Override
public int getCount()
{
return setings_Adapt_Catagories.length;
}
@Override
public Object getItem(int arg0)
{
return null;
}
@Override
public long getItemId(int position)
{
return 0;
}
@Override
public View getView(final int position, View convertView, ViewGroup parent)
{
SettingsAdptorViewHolder holder;
if (convertView == null)
{
convertView = mInflater.inflate(R.layout.adapter_settingslist, null);
holder = new SettingsAdptorViewHolder();
holder.settings_catagory = (TextView) convertView.findViewById(R.id.settings_lable_text);
holder.settings_list_checkbox = (ToggleButton) convertView.findViewById(R.id.settings_checkbox);
holder.settings_list_checkbox.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View v)
{
ToggleButton cb = (ToggleButton) v;
if (cb.isChecked() == true)
{
setings_Adapt_Catagories[position].setStatus("true");
}
else
{
setings_Adapt_Catagories[position].setStatus("false");
}
}
});
convertView.setTag(holder);
}
else
{
holder = (SettingsAdptorViewHolder) convertView.getTag();
}
if(setings_Adapt_Catagories[position].getStatus().equals("true")&&isNotificationEnnabled.equals("on"))
{
holder.settings_list_checkbox.setChecked(true);
}
else if(setings_Adapt_Catagories[position].getStatus().equals("false"))
{
holder.settings_list_checkbox.setChecked(false);
}
holder.settings_catagory.setText(setings_Adapt_Catagories[position].getDealName());
return convertView;
}
class SettingsAdptorViewHolder
{
TextView settings_catagory;
ToggleButton settings_list_checkbox;
}
}