0
我使用自定義列表視圖(其中有一個圖像和文本框作爲佈局),所有的數據都從類對象和圖像形式的web檢索,所有的東西是絕對正常運行唯一的事情是,在模擬器列表視圖不顯示任何異常行爲,但是當我部署它在設備上,列表視圖不滾動,因爲它應該做的。它只是爲了一點點和背景整個列表視圖的圖像消失,然後在滾動結束時出現。我應該在這裏做什麼是調用和填充列表視圖數據的代碼。android listview停止滾動背景圖像的第二個
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);
}
});
這裏是清單
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;
}
}
}
親切指導我,如果你知道我錯了,
感謝GOOD回覆
究竟發生了什麼?你的listView背景是黑色的? –
沒有它的白色或你可以用它定義的顏色,但是當我開始滾動時,背景消失,只要我滾動> –
請參閱Ajmal Salims的答案。在getView()方法中下載和創建圖像就像乞求糟糕的性能一樣。這應該是異步完成的,你也應該實現某種緩存。 – Ole