CheckBox
Значение по умолчанию не работает. Я дал значение CheckBox
на setcheck(true)
, а также дано в макете, и мне нужно передать проверенное значение в arraylist.По умолчанию checkbox with checked not working
Как использовать arraylist для отправки значений между двумя классами, как сохранить данные в активе db
в android.
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());
};