How to uncheck a checkbox in array adapter - android

I am trying to uncheck checkbox in listview array adapter on onItemClickListener.
its remain checked all the time.If i again click on it to uncheck it is not getting unchecked.
Can anyone over here please suggest me how to do it?
pagesresult = new JSONArray(getIntent().getStringExtra("pageResult"));
for (int i = 0; i < pagesresult.length(); i++) {
JSONObject json = pagesresult.getJSONObject(i);
Iterator<String> keys = json.keys();
while (keys.hasNext()) {
key = keys.next();
//pageValue = );
pageKeyArray.add(key);
pageArray.add(String.valueOf(json.get(key)));
System.out.println("Key :" + key + " Value :" + json.get(key));
Log.d(TAG, "pageKeyArray Check :" + pageKeyArray);
Log.d(TAG, "currentKey Check :" + pageArray);
}
}
alreadyBookedByUser = new JSONArray(getIntent().getStringExtra("alreadyBookedByUser"));
Log.d(TAG, "compositionCount Check :" + pagesresult);
Log.d(TAG, "compositionCount Check :" + alreadyBookedByUser);
} catch (JSONException e) {
e.printStackTrace();
}
done = (Button) findViewById(R.id.done);
findViewsById();
adapter = new ArrayAdapter<String>(this,android.R.layout.simple_list_item_multiple_choice,pageArray);
listView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
listView.setAdapter(adapter);
listView.setOnItemClickListener(this);
#Override
public void onClick(View v) {
if (v == done) {
SparseBooleanArray checked = listView.getCheckedItemPositions();
ArrayList<String> selectedItems = new ArrayList<String>();
for (int i = 0; i < checked.size(); i++) {
// Item position in adapter
position = checked.keyAt(i);
listView.setItemChecked(position, true);
Log.d(TAG, "Position check :" + position);
// Add sport if it is checked i.e.) == TRUE!
if (checked.valueAt(i)) {
selectedItems.add(adapter.getItem(position));
}
}
Log.d(TAG, "Page key array show :" + this.pageKeyArray);
Log.d(TAG, "selectedItems show :" + selectedItems);
int max = -1;
for(String value: selectedItems) {
int selectedIndex= this.pageArray.indexOf(value);
this.selectedPageIems.add(this.pageKeyArray.get(selectedIndex));
if(selectedIndex > max) {
max = selectedIndex;
}
}
String firstPageNumber = getFirstPageNumber(this.pageKeyArray.get(0));
String currentPageNumber = firstPageNumber;
String lastPageNumber = getLastPageNumber(this.pageKeyArray.get(max));
Log.d(TAG, "First Page Number :" + firstPageNumber);
Log.d(TAG, "Last Page Number :" + lastPageNumber);
Log.d(TAG, "selectedPageIndexes show :" + selectedPageIndexes);
Log.d(TAG, "selectedPageIems show :" + selectedPageIems);
String[] outputStrArr = new String[selectedItems.size()];
for (int i = 0; i < selectedItems.size(); i++) {
outputStrArr[i] = selectedItems.get(i);
}
try {
selectPages();
} catch (JSONException e) {
e.printStackTrace();
}
Intent intent = new Intent(getApplicationContext(),MyBookings.class);
session.setPageNumbers(firstPageNumber,currentPageNumber,lastPageNumber);
startActivity(intent);
}
}
#Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Log.d(TAG, "First Page Number :" + position);
for (int i=0; i<=position; i++){
listView.setItemChecked(i,true);
}
}

You check the checkboxes each time you press an item ?
#Override
public void onItemClick(AdapterView parent, View view, int position, long id) {
Log.d(TAG, "First Page Number :" + position);
for (int i=0; i<=position; i++){
listView.setItemChecked(i,true);
}
}
I don't see setItemChecked(i,false) anywhere

Related

NotifyDataSetChanged not working in arraylist using autocompletetextview in android

I want to update State list according to the country type in autocompletetextview. I have used the below code .It is working fine for the first time .I write country but once i edit the country name .It is not updating the state list(used notifyDataSetChanged but its not working).Please check the code .Thanks!
AutoCompleteTextView country_edit,state_edit;
for (int i = 1; i < global.getExcel().length; i++) {
String[] separated = global.getExcel()[i].split(",");
code = separated[0]; // this will contain "Fruit"
country = separated[1];
Log.e("length", code + "==" + country);
Log.e("sep", separated + "====" + global.getExcel()[i]);
countrylist.add(country);
codelist.add(code);
Log.e("countrylist", countrylist + "==");
}
//==============================================ArrayAdapter Country & state
final ArrayAdapter<String> country_adapter = new ArrayAdapter<String>
(this, R.layout.custom_autolistview_list, R.id.text1, countrylist);
country_edit.setThreshold(1);
country_edit.setAdapter(country_adapter);
final ArrayAdapter<String> state_adapter = new ArrayAdapter<String>
(this, R.layout.custom_autolistview_list, R.id.text1, State_array);
state_edit.setThreshold(1);
state_edit.setAdapter(state_adapter);
state_edit.setDropDownHeight(WRAP_CONTENT);
state_adapter.notifyDataSetChanged();
country_edit.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
// Log.e("country", country_edit.getText().toString());
country_str = country_edit.getText().toString();
// Log.e("country", country_str);
int index = countrylist.indexOf(country_str);
Log.e("index", index + "");
String code_index = codelist.get(index);
Log.e("code", code_index);
State_list.clear();
State_array.clear();
for (int i = 0; i < global.getState().length; i++) {
if (global.getState()[i].contains("," + code_index + ",")) {
String statelist = global.getState()[i];
Log.e("statelist", statelist);
State_list.add(statelist);
Log.e("State", State_list + "");
state_name = "";
for (int j = 0; j < State_list.size(); j++) {
String[] statelist_array = State_list.get(j).split(",");
state_name = statelist_array[0];
String state_code = statelist_array[1];
Log.e("state_code", state_code);
Log.e("state_name", state_name);
}
Log.e("Stateeeeeeeee", State_array + "");
State_array.add(state_name);
Log.e("Stateeeeeeeeeeeeeeee", State_array + "");
}
state_ll.setVisibility(View.VISIBLE);
}
state_adapter.notifyDataSetChanged();
}
});

notifyDataSetChanged not work in my activity

in my code when delete row of list view list view don't change.i use adapter.notifyDataSetChange() but it not word.this is my code : code make different position of class.
CustomList adapter;
Integer[] imageId;
public String[] _Data2;
public int positionAll;
ArrayList<ArrayList<String>> _Data = new ArrayList<ArrayList<String>>();
DataBase data = new DataBase(Show_Code.this, "MELK_TBL");
try {
data.open();
_Data = data.GetData();
imageId = new Integer[_Data.size()];
_Data2 = new String[_Data.size()];
for (int i = 0; i < _Data.size(); i++) {
imageId[i] = R.drawable.municipal;
_Data2[i] = _Data.get(i).get(1) + "_" + _Data.get(i).get(2) + "_" + _Data.get(i).get(3) + "_" + _Data.get(i).get(4) + "_" + _Data.get(i).get(5) + "_" + _Data.get(i).get(6) + "_0";
}
adapter = new CustomList(Show_Code.this, _Data2, imageId);
data.close();
} catch (Exception e) {
Toast.makeText(getApplication(), e.toString(), Toast.LENGTH_LONG).show();
}
list.setAdapter(adapter);
list.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
#Override
public boolean onItemLongClick(AdapterView<?> parent, View view,
int position, long id) {
try {
data.open();
data.Delete(_Data.get(position).get(1), _Data.get(position).get(2), _Data.get(position).get(3), _Data.get(position).get(4), _Data.get(position).get(5), _Data.get(position).get(6), _Data.get(position).get(7));
data.close();
adapter.notifyDataSetChanged();
} catch (Exception e) {
Toast.makeText(getApplicationContext(), e.toString(), Toast.LENGTH_LONG).show();
}
return true;
}
});
please help me,i don't any time for it :(
As the size of Array is not changed at run time so u need to create new adapter and set again to list
You have to add this code in onItemLongClick
data.open();
_Data = data.GetData();
imageId = new Integer[_Data.size()];
_Data2 = new String[_Data.size()];
for (int i = 0; i < _Data.size(); i++) {
imageId[i] = R.drawable.municipal;
_Data2[i] = _Data.get(i).get(1) + "_" + _Data.get(i).get(2) + "_" + _Data.get(i).get(3) + "_" + _Data.get(i).get(4) + "_" + _Data.get(i).get(5) + "_" + _Data.get(i).get(6) + "_0";
}
adapter = new CustomList(Show_Code.this, _Data2, imageId);
data.close();
list.setAdapter(adapter)
you are passing _Data2 object in adapter. You should update same object after deleting from data. Try adding this before data.close() in onItemLongClick(AdapterView<?> parent, View view,int position, long id) method:
_Data = data.GetData();
imageId = new Integer[_Data.size()];
_Data2.clear();
for (int i = 0; i < _Data.size(); i++) {
imageId[i] = R.drawable.municipal;
_Data2[i] = _Data.get(i).get(1) + "_" + _Data.get(i).get(2) + "_" + _Data.get(i).get(3) + "_" + _Data.get(i).get(4) + "_" + _Data.get(i).get(5) + "_" + _Data.get(i).get(6) + "_0";
}
Don't create new object of _Data2. Just clear same object and add whole data in it again and after that you can call adapter.notifyDataSetChanged() then this will get updated automatically.
After deleting the values you need to pass the new arraylist in which you had removed all those values and then notify the adapter class. In your case see the below code
list.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
#Override
public boolean onItemLongClick(AdapterView<?> parent, View view,
int position, long id) {
try {
data.open();
data.Delete(_Data.get(position).get(1));
data.close();
**//Edited code...**
_Data.get(position).remove(1);
adapter.refreshView(_Data);
**//Edited code...**
} catch (Exception e) {
Toast.makeText(getApplicationContext(), e.toString(), Toast.LENGTH_LONG).show();
}
return true;
}
});
And in adapter class refreshview method will be like below,
public void refreshView(String[] _Data) {
this._Data = _Data;
notifyDataSetChanged();
}
By this way you can notify the data. For example I have deleted only one value and notify.
Hope this is helpful :)
You'll need to reorganize your code, using Methods, only for Select you databe again and do the list.setAdapter(adapter); then use adapter.notifyDataSetChanged();

I would like to spinner in recycle view list in android

I have retrieve data from json and set in onbind in recycle list view like
how can add value in spinner product.setQuantity(quantity); for each row
private ArrayList<ProductBySubCategory> parseJSONResponse(JSONArray response) {
ArrayList<ProductBySubCategory> listProducts = new ArrayList<ProductBySubCategory>();
if (response != null && response.length() > 0) {
try {
StringBuilder data = new StringBuilder();
JSONArray jsonArray = response;
for (int i = 0; i < jsonArray.length(); i++) {
JSONObject jsonObject = jsonArray.getJSONObject(i);
String pName = jsonObject.getString(KEY_NAME);
String pPrice = jsonObject.getString(KEY_PRICE);
String pUrlThumbnail = AppConfig.URL_THUBMNAIL_BASE + jsonObject.getString(KEY_THUMBNAIL);
String pSNo = jsonObject.getString(KEY_SNO);
String sellerName = jsonObject.getString(KEY_SELLER_NAME);
String qrValue = jsonObject.getString(KEY_QRVALUE);
String quantity = jsonObject.getString(KEY_QUANTITY);
data.append(pName + " " + pPrice + " " + pUrlThumbnail + " " + pSNo + " " + sellerName +" "+qrValue+ " "+quantity+ "\n");
ProductBySubCategory product = new ProductBySubCategory();
product.setpName(pName);
product.setSellerName(sellerName);
product.setQrValue(qrValue);
product.setpPrice(getString(R.string.material_icon_rupees)+pPrice);
product.setpUrlThumbnail(pUrlThumbnail);
product.setpSNo(pSNo);
product.setQuantity(quantity);
listProducts.add(product);
}
Log.d("Lifecycle2", listProducts.toString());
} catch (JSONException e) {
Log.d("Lifecycle", "Inside JSON EXCEPTION: " + e);
}
}
return listProducts;
}
In above code i want to quantity in spinner for each row.
I have set value in adapter in below code but I didn't set quantity in text view because I want to this value set in spinner and I have array value for spinner for each product in list and now what should I do for set value in spinner like this image for each item if possible please give me some code.
#Override
public void onBindViewHolder(final ViewHolderProducts holder, int position) {
ProductBySubCategory currentProduct = productArrayList.get(position);
holder.productName.setText(currentProduct.getpName());
holder.sellerName.setText(currentProduct.getSellerName());
holder.qrValue.setText(currentProduct.getQrValue());
holder.productPrice.setText(currentProduct.getpPrice());
holder.btnBuy.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
RelativeLayout relativeLayout = (RelativeLayout) view.getParent();
TextView textView = (TextView) relativeLayout.findViewById(R.id.qrValue);
String qrText = (String) textView.getText();
Log.d("Abhinav", "qrValue" +qrText);
if (buyItemClickListener != null) {
buyItemClickListener.buttonClicked(qrText);
}
}
});
String urlThumbnail = currentProduct.getpUrlThumbnail();
if (urlThumbnail != null) {
imageLoader.get(urlThumbnail, new ImageLoader.ImageListener() {
#Override
public void onResponse(ImageLoader.ImageContainer response, boolean b) {
holder.productThumbnail.setImageBitmap(response.getBitmap());
}
#Override
public void onErrorResponse(VolleyError volleyError) {
}
});
}
}

How to find id of selected array in arraylist in android

I have one array list, contains list of countries, next i selected particular student that is in string array. so how to find that selected string array of respective array list ids.
Code:
public class MainActivity extends Activity {
ArrayList<String> s = new ArrayList<String>();
private String log_email, log_pass, selectedcon = "";
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
s.add("Nepal");
s.add("Korea");
s.add("Sri Lanka");
s.add("India");
s.add("Pakistan");
s.add("China");
s.add("Australia");
s.add("Bhutan");
String s1 = "Australia, Nepal, India, Korea";
String selectedHobbies[] = s1.split(",");
Log.d("TAG", "ddddd--" + "----"
+ selectedHobbies.length);
if (selectedHobbies.length != 0) {
for (int i = 0; i < s.size(); i++) {
for (int j = 0; i < selectedHobbies.length; j++) {
String t = selectedHobbies[j];
if (Arrays.asList(s.get(i)).contains(t)) {
selectedcon = selectedcon + i + ",";
Log.d("TAG", "Testing--" + i + "----"
+ selectedcon);
}
// int match=false;
}
}
}
Log.d("TAG", "Selected--ddddddddd---" + selectedcon);
}
}
I want of find ids of selected countries of array list.
ArrayList<String> s = new ArrayList<String>();
s.add("Nepal");
s.add("Korea");
s.add("Sri Lanka");
s.add("India");
s.add("Pakistan");
s.add("China");
s.add("Australia");
s.add("Bhutan");
String s1 = "Australia, Nepal, India, Korea";
String selectedHobbies[] = s1.split(",");
for (int i=0;i<s.size();i++) {
for (int j=0;j<selectedHobbies.length;j++) {
if (s.get(i).contains(selectedHobbies[j])) {
Log.d("xxx", "found");
Log.d("xxx", "s index " + i);
Log.d("xxx", "hobbies index " + j);
}
}
}
Corrected.

How to keep track of item-checking in a custom ListView using a custom ArrayAdapter?

My stack is really overflow, I mean currently my brain can't think of a way to solve the below problem (Although I'm through trial-and-errors many days). All I want to do is a sreen for deletion purpose like (http://asset0.cbsistatic.com/cnwk.1d/i/tim/2010/11/18/Foreman_11654166_1073_com.probosoft.masscontactsdelete0_257x386.png)
I have a layout of a list-view-item like this (log_view.xml):
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="5dp" >
<TextView
android:id="#+id/date_view"
android:gravity="top|left"
android:textStyle="bold"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentLeft="true" />
<TextView
android:id="#+id/value_view"
android:gravity="top|left"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/date_view"
android:layout_alignParentLeft="true" />
<CheckBox
android:id="#+id/del_box"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginRight="5dp"
android:visibility="gone"
android:focusable="false"
android:focusableInTouchMode="false" />
</RelativeLayout>
And this is my custom Adapter:
class LogViewAdapter extends ArrayAdapter<Log> {
public ArrayList<Boolean> checkList;
private int layoutResourceId;
private List<Log> logList;
Context context;
public LogViewAdapter(Context context, int layoutResourceId, List<Log> data) {
super(context, R.layout.log_view, data);
this.layoutResourceId = layoutResourceId;
this.logList = data;
this.context = context;
checkList = new ArrayList<Boolean>();
for (int i = 0; i < logList.size(); i ++) {
checkList.add(false);
}
}
#Override
public View getView(final int position, View convertView, ViewGroup parent) {
LogHolder logholder = null;
// Unidentified view
if(convertView == null) {
LayoutInflater inflater = ((Activity)context).getLayoutInflater();
convertView = inflater.inflate(layoutResourceId, parent, false);
// Create a new holder
logholder = new LogHolder();
logholder.del_box = (CheckBox)convertView.findViewById(R.id.del_box);
logholder.del_box.setChecked(false);
final int iFinal = position;
logholder.del_box.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
checkList.set(iFinal, buttonView.isChecked());
}
});
logholder.date_view = (TextView)convertView.findViewById(R.id.date_view);
logholder.value_view = (TextView)convertView.findViewById(R.id.value_view);
convertView.setTag(logholder);
}
// Identified view
else {
logholder = (LogHolder) convertView.getTag();
}
if (null != logList) {
if (null == checkList.get(position)) {
android.util.Log.e("getView", "Checklist null at " + position);
}
//logholder.del_box.setChecked((boolean)checkList.get(position));
logholder.date_view.setText(logList.get(position).date);
logholder.value_view.setText(logList.get(position).value);
}
android.util.Log.e("getView", " at " + position + ", value = " + logholder.value_view.getText().toString());
return convertView;
}
static class LogHolder {
TextView date_view;
TextView value_view;
CheckBox del_box;
}
}
Here 's my Activity:
public class LoggingActivity extends Activity {
//private EditText edt_name;
//private EditText edt_value;
private List<Log> logList;
private LogViewAdapter lw_adapter;
private ListView listView;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.log_list);
//setContentView(android.R.layout.simple_list_item_multiple_choice);
logList = loadLog();
listView = (ListView)findViewById(R.id.log_list);
lw_adapter = new LogViewAdapter(this, R.layout.log_view, logList);
//lw_adapter = new LogViewAdapter(this, android.R.layout.simple_list_item_multiple_choice, logList);
listView.setAdapter(lw_adapter);
}
/** implements for the MENU soft-key. Android 2.3.x */
#Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.layout.log_menu, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// IMPORTANT: listView.getChildAt(index) will only return the
// VISIBLE views in our current screen
if (null == listView) {
android.util.Log.e("onOptionsItemSelected", "list view null");
return true;
}
for (int i = 0; i < listView.getChildCount(); i++) {
if (null == listView.getChildAt(i)) continue;
CheckBox cb = (CheckBox) listView.getChildAt(i).findViewById(R.id.del_box);
if (null == cb) {
android.util.Log.e("CB", "CheckBox at i = " + i + " null");
return true;
}
final int iFinal = i + listView.getFirstVisiblePosition();
cb.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
listView.setItemChecked(iFinal, buttonView.isChecked());
lw_adapter.checkList.set(iFinal, buttonView.isChecked());
}
});
SparseBooleanArray selectedItems = listView.getCheckedItemPositions();
for (int j = 0; j < selectedItems.size(); j++) {
if (selectedItems.get(j)) {
android.util.Log.e("CHECKED", "Row "+ j + ", value = " + logList.get(j).value);
}
else {
android.util.Log.e("CHECKED", "Row "+ j + " not checked");
}
}
cb.setVisibility(View.VISIBLE);
cb.setEnabled(true);
}
File folder = new File(Environment.getExternalStorageDirectory(), "50802566/logs");
// Handle item selection
switch (item.getItemId()) {
case R.id.log_sort:
Collections.sort(logList, Log.COMPARE_BY_VALUE);
lw_adapter.notifyDataSetChanged();
return true;
case R.id.log_del:
for (int i = 0; i < logList.size(); i++) {
if (null == lw_adapter.checkList.get(i)) {
android.util.Log.e("DEL", "checklist["+ i + "] = null");
continue;
}
if (true == lw_adapter.checkList.get(i)) {
// Delete correlative xml file
Date date = null;
try {
date = new SimpleDateFormat("dd/MM/yyyy - HH:mm:ss").parse(logList.get(i).date);
} catch (ParseException e) {
e.printStackTrace();
}
String filename = new SimpleDateFormat("dd_MM_yyyy - HH_mm_ss").format(date) + ".xml";
File toDelete = new File(folder, filename);
if (!toDelete.delete()) {
android.util.Log.e("DEL", "File " + filename + ": not deleted or not existed");
}
// Update the UI
//lw_adapter.remove(logList.get(i));
//lw_adapter.checkList.remove(i);
logList.set(i, null);
lw_adapter.checkList.set(i, null);
android.util.Log.e("DEL", "Deleted " + i + ", size now = " + logList.size());
}
}
for (int i = 0; i < logList.size(); i ++) {
if (null == logList.get(i)) {
logList.remove(i);
lw_adapter.checkList.remove(i);
}
}
lw_adapter.notifyDataSetChanged();
// Refresh the checklist
for (int i = 0; i < lw_adapter.checkList.size(); i ++) {
lw_adapter.checkList.set(i, false);
}
for (int i = 0; i < listView.getChildCount(); i++) {
if (null == listView.getChildAt(i)) continue;
CheckBox cb = (CheckBox) listView.getChildAt(i).findViewById(R.id.del_box);
cb.setChecked(false);
}
return true;
default:
return super.onOptionsItemSelected(item);
}
}
private ArrayList<Log> loadLog() {
/** Access folder "my_logs" in external memory */
File baseDir = new File(Environment.getExternalStorageDirectory().getAbsolutePath() +
File.separator +
"50802566/logs");
if (!baseDir.exists()) { baseDir.mkdirs(); }
File[] list_file = baseDir.listFiles();
/** For internal memory */
//File[] list_file = this.getFilesDir().listFiles();
for (int i = 0; i < list_file.length; i ++) {
//android.util.Log.e("PRINTLN", list_file[i].getPath());
}
int l = list_file.length;
ArrayList<Log> list = new ArrayList<Log>();
while (l-- > 0) {
File file = list_file[l];
FileInputStream fin = null;
LogReader logr = new LogReader();
try {
fin = new FileInputStream(file);
list.add(list_file.length - l - 1, logr.read(fin));
fin.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (XmlPullParserException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
return list;
}
}
The problems are:
I can't keep track of the boolean values of each CheckBox. For example if I sort the logList (my database) then "notifyDataSetChanged" to the listView, but my checkList (which contains booleans of CheckBoxes) is still the same, and strange things happen. How can I apply EXACTLY all the sorting-operation of one list to another one? (IMO, "synchronized sorting" or something like that...)
As you can see, I've try to solve #1 by getting the del_box (my CheckBox id) from its row, then set its "OnCheckedChangeListener" to do the assigning (once checked, it will update relative value in the boolean List "checkList"). But strange things happen again:
When checked a row and scroll down, I see another one is (automatically) checked.
When scrolling back, the previous checked one... is unchecked (automatically, of course).
Maybe the Adapter is re-using the wrong Views/values but I have no clue of how to make it do things right... >"<
Your helps and guides are great. Sample codes of yours will be more than perfect to me... (I'm really exhausted right now >"<)
UPDATE:
I've find a way to (somehow) solve it, but maybe it's against API behavior of Android... If you have safer solution, plz let me know ^^
As mentioned in my second comment, here's the code:
#Override
public void onCheckedChanged(CompoundButton cb, boolean isChecked) {
int graphicalPos = -1;
// This is top view on the screen for sure
if (((View)cb.getParent()).getTop() < 0) {
graphicalPos = 0;
}
else if (((View)cb.getParent()).getTop() == 0) {
graphicalPos = (int) (((View)cb.getParent()).getTop() / ((View)cb.getParent()).getHeight());
}
else if (((View)cb.getParent()).getTop() > 0) {
graphicalPos = (int) (((View)cb.getParent()).getTop() / ((View)cb.getParent()).getHeight());
if (listView.getChildAt(0).getTop() < 0) {
graphicalPos = graphicalPos + 1;
}
else {
android.util.Log.e("NOT PLUS", "First Top = " + listView.getChildAt(0).getTop());
}
}
int dataPos = graphicalPos + listView.getFirstVisiblePosition();
lw_adapter.checkList.set(dataPos, isChecked);
android.util.Log.e("onCheckedChanged", "Checked row " + dataPos + ", graphicalPos = " + graphicalPos + ", top = " + ((View)cb.getParent()).getTop() + ", firstVisible = " + listView.getFirstVisiblePosition());
}

Categories

Resources