简体   繁体   中英

android listview stopping for a second for background image on scrolling

i am using custom list-view (which have one image and text boxes as layout), all the data is retrieved from the class objects and image form web, all the things is running absolutly fine the only things is that in emulator the list-view don't show any abnormal behaviour but when i deploy it on device ,the listview does not scroll as it is supposed to do.it struck just for a bit and background image for whole list view disappear and then appear when scrolling ends.what should i do here is the code for calling and populating the list-view data.

public void item_display(){
    String[] separated = eventIDForList.split(",");
    final List_class ObjListClass[] = new List_class[separated.length];
    for(int i=0;i<separated.length;i++){
        String temp=separated[i];
        eventIdVal=Integer.parseInt(temp);
        Log.d("events id for displaying id",eventIdVal+"");
        ObjListClass[i]=new List_class();
        ObjListClass[i]=new List_class(FBEvents.getInstance().object_info.get(eventIdVal).fbEventId,FBEvents.getInstance().object_info.get(eventIdVal).fbPic,"Title:  "+FBEvents.getInstance().object_info.get(eventIdVal).fbName,"desc :"+FBEvents.getInstance().object_info.get(eventIdVal).fbDescription,"location :"+FBEvents.getInstance().object_info.get(eventIdVal).fbLocation,FBEvents.getInstance().object_info.get(eventIdVal).fbAttending_count);

   }
    List_class_adapter adapter = new List_class_adapter(this,
            R.layout.listview_item_row, ObjListClass);
    listView1 = (ListView)findViewById(R.id.listView2);

    listView1.setAdapter(adapter);

   // View header = (View)getLayoutInflater().inflate(R.layout.listview_header_row, null);
   // listView1.addHeaderView(header);
   // listView1.setAdapter(adapter);
    listView1.setOnItemClickListener(new OnItemClickListener()
    {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long duration)
            {

            Log.d("position val",position+"");
            eventIdForDetails=ObjListClass[position].eventId;
            Log.d("String val",eventIdForDetails);
            eventdetails(view);

            }
    });  

and here is the adapter for the list

public class List_class_adapter extends ArrayAdapter<List_class>{

Context context;
int layoutResourceId;   
List_class data[] = null;

public List_class_adapter(Context context, int layoutResourceId, List_class[] data) {
    super(context, layoutResourceId, data);
    this.layoutResourceId = layoutResourceId;
    this.context = context;
    this.data = data;
}

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    View row = convertView;
    ListHolder holder = null;

    if(row == null)
    {
        LayoutInflater inflater = ((Activity)context).getLayoutInflater();
        row = inflater.inflate(layoutResourceId, parent, false);

        holder = new ListHolder();
        holder.imgIcon = (ImageView)row.findViewById(R.id.imgIcon);
        holder.txtTitle = (TextView)row.findViewById(R.id.txtTitle);
        holder.txtTitle2 = (TextView)row.findViewById(R.id.txtTitle2);
        holder.txtTitle3 = (TextView)row.findViewById(R.id.txtTitle3);
        holder.txtTitle4 = (TextView)row.findViewById(R.id.txtTitle4);

        row.setTag(holder);

    }
    else
    {
        holder = (ListHolder)row.getTag();
    }

    List_class list_class = data[position];
    String url = list_class.pic;           
    Drawable image =ImageOperations(this,url);
    holder.txtTitle.setText(list_class.title);
    holder.imgIcon.setImageDrawable(image);
    holder.txtTitle2.setText(list_class.description);
    holder.txtTitle3.setText(list_class.startdate);
    holder.txtTitle4.setText(list_class.attending_count);

    return row;
}

static class ListHolder
{
    ImageView imgIcon;
    TextView txtTitle;
    TextView txtTitle2;
    TextView txtTitle3;
    TextView txtTitle4;


}




public Object fetch(String address) throws MalformedURLException,
IOException {
    URL url = new URL(address);
    Object content = url.getContent();
    return content;
}  

private Drawable ImageOperations(List_class_adapter list_class_adapter, String url) {
    try {
        InputStream is = (InputStream) this.fetch(url);
        Drawable d = Drawable.createFromStream(is, "src");
        return d;
    } catch (MalformedURLException e) {
        return null;
    } catch (IOException e) {
        return null;
    }
}

}

kindly guide me if you know where i am wrong

Thanks for GOOD replies

I think you should use Thread or AsyncTask . This will avoid the lags and run the background process in another Thread

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM