Android : Refresh data in a Android's ListView after webservice called?

on Sunday, August 17, 2014


Here is what I want to do. My MainActivity contains an extended adapter and a list of items:



public class MainActivity extends Activity
{
private ArrayList<SliderItem> sliderItems;
private SliderListAdapter adapter;

// ...

@Override
protected void onCreate(Bundle savedInstanceState)
{
adapter = new SliderListAdapter(getApplicationContext(), sliderItems);
sliderList.setAdapter(adapter);
}
}


Every item contains a title, a count and a boolean to display it or not.



public class SliderItem
{
private String title;
private String count = "0";
private boolean isCounterVisible = false;
// ...
}


And my adapter handles the displaying of the items :



public class SliderListAdapter extends BaseAdapter
{
private Context context;
private ArrayList<SliderItem> sliderItems;

@Override
public View getView(int position, View convertView, ViewGroup parent)
{
TextView txtCount = (TextView) convertView.findViewById(R.id.counter);
// ...

if(sliderItems.get(position).isCounterVisible()){
txtCount.setText(sliderItems.get(position).getCount());
} else {
txtCount.setVisibility(View.GONE);
}
}

// ...
}


What I want to do now is to display a count after getting it from a webservice, so dynamically reload my ListView content. I know how to use AsyncTask and Services, but I don't know where to implement it... so what should I do? Thanks for your help.


0 comments:

Post a Comment