CheckBox
默認值不起作用。我已經給出了CheckBox
值setcheck(true)
,並在佈局中給出,我需要將選中的值傳遞給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());
};