I've a listview and each list item has a progressbar. I want to control that progressbar in a asynktask in this way : in onPreExecute() progressbar set to visible, in onPostExecute() the progressbar set to gone. I've tried with the following code but in this way sometimes it doesn't work and the progressbar is always visible:
private class sendMsg extends AsyncTask<String, String, String>{
String mess;
int ind;
@Override
protected void onPreExecute(){
ind=lv.getLastVisiblePosition();
addItems(mess, false,false,nick,null); //here I add the item to listview
}
@Override
protected String doInBackground(String... arg0) {.....}
@Override
protected void onPostExecute(String temp){
if(temp.equals("SUCCESS")) {
View v = lv.getChildAt(ind+1);
ProgressBar pbb = (ProgressBar) v.findViewById(R.id.messric);
pbb.setVisibility(View.GONE); }
}
listitem.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="wrap_content" >
<LinearLayout
android:id="@+id/wrapper"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
>
<LinearLayout
android:id="@+id/bollavera"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:orientation="vertical"
android:layout_margin="10dp"
>
<TextView
android:id="@+id/comment"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="left"
android:layout_margin="5dip"
android:paddingLeft="10dip"
android:textColor="@android:color/primary_text_light"
android:textSize="18dp" />
<ProgressBar
android:id="@+id/messric"
style="?android:attr/progressBarStyleSmall"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:visibility="gone" />
</LinearLayout>
</LinearLayout>
</RelativeLayout>
Another problem on this code is : if try to make the progressbar VISIBLE from the adapter, when there will be other items, the item before them has again a progressbar, also if i rotate the screen. I can't make visible that progressbar in the method onPreExecute() because i don't know if the item is just visible because i add the item 1 row before.