【发布时间】:2015-10-21 07:45:31
【问题描述】:
CheckBox 默认值不起作用。我已经通过setcheck(true) 给出了CheckBox 的值,并且在布局中也给出了,我需要将检查的值传递给arraylist。
如何使用arraylist在两个类之间发送值如何在android中将数据保存在资产db中。
public class CustomListAdapter extends ArrayAdapter<String>
{
RetrieveFromDB sqlConn;
private final Context context;
private ArrayList<String> resArray;
public static ArrayList<String> selitemsList=new ArrayList<String>();
public CustomListAdapter(Context context, ArrayList<String> resArray)
{
super(context, R.layout.categorylist, resArray);
// TODO Auto-generated constructor stub
this.context = context;
this.resArray = resArray;
}
public View getView(final int position, View convertView, ViewGroup parent) {
try{
LayoutInflater inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View rowView = inflater.inflate(R.layout.list_item_2, parent, false);
CheckBox chk=(CheckBox)rowView.findViewById(R.id.checkBox1);
TextView list= (TextView) rowView.findViewById(R.id.text2);
list.setText(resArray.get(position).toString());
sqlConn=new RetrieveFromDB(context);
selitemsList=sqlConn.displaySelectedItems(EditSelectedItems.sel_category);
sqlConn.close();
if(selitemsList.contains(list.getText().toString()))
chk.setChecked(true);
else
chk.setChecked(false);
chk.setOnCheckedChangeListener(new OnCheckedChangeListener()
{
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked)
{
// TODO Auto-generated method stub
if(isChecked)
{
CategoryListView.st.add(resArray.get(position).toString());
selitemsList.add(resArray.get(position).toString());
};
【问题讨论】: