I have a listView with an editText and a checkBox, what I want to do is that the checkboxes in the listView appear checked if this is the value of the editText in an arrayList I leave you some code so that it can be identified:
The xml of the fields in the listView, very simple the 2 elements that I have commented:
<CheckBox
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:id="@+id/checkbox"
android:gravity="center_vertical"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/articulo"/>
Here is the arrayList that collects from a bd the values that should appear checked
ArrayList articulosCheck = new ArrayList(Utility.dbHelper.getShowMainArt(spinner.getSelectedItem().toString()));
This functionality I want to be executed when the value of a spinner changes, the listener of the spinner is the following:
spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
listaart[0] = new ArrayList(Utility.dbHelper.getArticlesByFam(spinner.getSelectedItem().toString()));
listView.setAdapter(new GArticleAdapter(getActivity(), listaart[0]));
ArrayList articulosCheck = new ArrayList(Utility.dbHelper.getShowMainArt(spinner.getSelectedItem().toString()));
Log.i("DGA ","articulosCheck "+articulosCheck);
/*for (int i = 0; i<listView.getCount();i++){
Log.i("DGA","Count "+ i);
LinearLayout itemLayout = (LinearLayout) listView.getChildAt(i);
CheckBox cb = (CheckBox) itemLayout.findViewById(R.id.checkbox);
for (int g = 0; g<listaart.length;g++) {
for (int f = 0; f < articulosCheck.size(); f++) {
Log.i("DGA ", "g "+ g);
Log.i("DGA ", "f "+ f);
if (g == f){}
}
}
}*/
}
As you can see I have tried to nest for loops to get the value of the editText from the listView and compare them with the values in the arrayList of values to check but it has not worked.
If you can give me opinions on how to solve it because I do not know how to interpret the process.
Greetings.