Search code examples
android-listviewandroid-asynctaskscroll

how to smooth scroll listview like ios in android?


I am use data from web using XML parser and setting data using custom adapter for this use asyncTask . My problem is that some devices like Samsang duos,gallaxy work perfectly but on micromax devices it will not work properly.

My adapter is

public class HallBookingAdapter extends ArrayAdapter<MyHall> {

private Context context;

private ArrayList<MCCIAHall> halls;

private int resource;

MyHall objHall;

public int count;

View view;

public static Boolean isScrollingHalls=true;

LayoutInflater inflater;

static class HallBookingHolder
{
    public TextView txtTitle,txtLocation,txtCapacity,txtCapacityTitle;
    public ImageView imgHall;
    public LinearLayout hallBookingLayout;
}

public HallBookingAdapter(Context context, int resource, ArrayList<MyHall> halls) {
    super(context, resource, halls);

    this.context=context;
    this.halls=halls;
    this.resource=resource;

    inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}

@Override
public int getCount() {
    count=halls.size();
    return halls.size();
}

@Override
public View getView(final int position, View convertView, ViewGroup parent) {

    view=convertView;

    objHall=halls.get(position);

    HallBookingHolder holder=new HallBookingHolder();

    if (convertView==null) {
        view = inflater.inflate(resource, null);

        holder.txtTitle=(TextView)view.findViewById(R.id.txtListHallTitle);
        holder.txtLocation=(TextView)view.findViewById(R.id.txtListHallLocation);
        holder.txtCapacity=(TextView)view.findViewById(R.id.txtListHallCapacity);
        holder.txtCapacityTitle=(TextView)view.findViewById(R.id.txtListHallCapacityHeadding);

        holder.imgHall=(ImageView)view.findViewById(R.id.imgListHall);

         view.setTag(holder);
    }
    else
    {
        holder = (HallBookingHolder)convertView.getTag();
    }

    //Creating the Font to the text
    Typeface tfLight = Typeface.createFromAsset(context.getAssets(),"OpenSans-Light.ttf");
    Typeface tfRegular = Typeface.createFromAsset(context.getAssets(),"OpenSans-Regular.ttf");
    Typeface tfsemiBold = Typeface.createFromAsset(context.getAssets(),"OpenSans-Semibold.ttf");

    //Setting the font
    holder.txtTitle.setTypeface(tfRegular);
    holder.txtLocation.setTypeface(tfLight);
    holder.txtCapacity.setTypeface(tfsemiBold);
    holder.txtCapacityTitle.setTypeface(tfLight);

//Setting data to textview and image
    holder.txtTitle.setText(objHall.hallName);
    holder.txtLocation.setText(objHall.location);
    holder.txtCapacity.setText(objHall.capacity);

    //Using Guild Library Image Load using image web url
    String imgurl=objHall.getImageUrl();
    Glide.load(imgurl).centerCrop().into(holder.imgHall);

    view.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent intent=new Intent(context, HallDetailsActivity.class);
            intent.putExtra("position", position);
            context.startActivity(intent);
        }
    });
    return view;
}

}


Solution

  • read it listview smooth-scrolling

    Using a background thread ("worker thread") removes strain from the main thread so it can focus on drawing the UI. In many cases, using AsyncTask provides a simple way to perform your work outside the main thread. AsyncTask automatically queues up all the execute() requests and performs them serially. This behavior is global to a particular process and means you don’t need to worry about creating your own thread pool.

    check this too http://www.itworld.com/development/380008/how-make-smooth-scrolling-listviews-android