Sunday, July 10, 2011

[android-developers] Re: ListView with CheckBox

You are trying to say you want to hide the checkbox on previously
clicked item and then show it on the currently clicked item? You can
edit it with the getView() method or do something like this


private class UI extends AsyncTask <View, String, View>
{
public View viewItem=null;
public UI(View v)
{
this.viewItem=v;
}
@Override
protected View doInBackground(View... arg0) {

return viewItem;
}

@Override
protected void onPreExecute() {

for(int i = 0; i <= listView.getLastVisiblePosition(); i++)
{
if(listView.getChildAt(i)!= null)
{

(listView.getChildAt(i).findViewById(R.id.yourcheckbox)).setVisibility(View.GONE);


}
}

super.onPreExecute();
}

@Override
protected void onPostExecute(View result) {


((CheckBox)result.findViewById(R.id.yourcheckbox)).setVisibility(View.VISIBLE);
//or change the state of the checkbox, your call :)
super.onPostExecute(result);
}

}

Remember, you can modify your userinterface only from UI thread. So
implementing AsyncTask you should do the modification in
onPreExecute() or in onPostExecute() methods. In your case in
onPreExecute you do hiding on the previous items view child and in
oPostExecute you do showing....

I hope this is what you are looking for.

--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

1 comment:

  1. How can i perfrom this:
    I have a layout for ListView:
    For ListView Rows Layout i have three elements:
    Such as Checkbox, textView,textView.
    I have a MENU: with 4 menuItem: Refresh, Edit, Next, Previous
    When refresh is clicked: i use a BroadCastReciever and then parse the data and set it into model class. and the listview is populated. and here i need to hide checkbox and when EDIT MENU ITEM is clicked i need to show checkbox.
    Please help

    ReplyDelete