我正在使用自定义列表视图(具有一个图像和文本框作为布局),所有数据都是从类对象和图像表单 web 中检索的,所有的东西都运行得非常好,唯一的事情是在模拟器中的列表 -视图没有显示任何异常行为,但是当我在设备上部署它时,列表视图没有按预期滚动。它只敲了一下,整个列表视图的背景图像消失,然后在滚动结束时出现。什么我应该在这里做的是调用和填充列表视图数据的代码。
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;
}
}
}
如果你知道我错在哪里,请指导我
感谢您的回复