Hoạt động của tôi bao gồm GridView chứa hơn 40 thành phần. Sau khi bắt đầu hoạt động, người dùng có thể thấy tối đa 15 mục (3 hàng, 5 mục trong mỗi hàng). Tôi đã viết trong getView() cơ thể để vượt qua với số LogCat nhận xem:Nhiều cuộc gọi getView() trong GridView
Log.i("getView()", "GETTING VIEW_POSITION[" + String.valueOf(position) + "]" + (convertView != null?convertView.toString():"null"));
Sau khi khởi chạy ứng dụng của tôi, tôi có được đăng nhập như:
02-09 14:34:56.900: INFO/getView()(388): GETTING VIEW_POSITION[0]null
02-09 14:34:57.300: INFO/getView()(388): GETTING VIEW_POSITION[0][email protected]
02-09 14:34:57.300: INFO/getView()(388): GETTING VIEW_POSITION[1]null
02-09 14:34:57.400: INFO/getView()(388): GETTING VIEW_POSITION[2]null
02-09 14:34:57.510: INFO/getView()(388): GETTING VIEW_POSITION[3]null
02-09 14:34:57.620: INFO/getView()(388): GETTING VIEW_POSITION[4]null
02-09 14:34:57.720: INFO/getView()(388): GETTING VIEW_POSITION[5]null
02-09 14:34:57.840: INFO/getView()(388): GETTING VIEW_POSITION[6]null
02-09 14:34:57.930: INFO/getView()(388): GETTING VIEW_POSITION[7]null
02-09 14:34:58.273: DEBUG/dalvikvm(388): GC freed 3530 objects/322744 bytes in 270ms
02-09 14:34:58.280: INFO/getView()(388): GETTING VIEW_POSITION[8]null
02-09 14:34:58.300: INFO/getView()(388): GETTING VIEW_POSITION[9]null
02-09 14:34:58.320: INFO/getView()(388): GETTING VIEW_POSITION[10]null
02-09 14:34:58.340: INFO/getView()(388): GETTING VIEW_POSITION[11]null
02-09 14:34:58.360: INFO/getView()(388): GETTING VIEW_POSITION[12]null
02-09 14:34:58.380: INFO/getView()(388): GETTING VIEW_POSITION[13]null
02-09 14:34:58.400: INFO/getView()(388): GETTING VIEW_POSITION[14]null
02-09 14:34:59.220: INFO/getView()(388): GETTING VIEW_POSITION[0]null
02-09 14:34:59.490: INFO/getView()(388): GETTING VIEW_POSITION[0][email protected]
Tôi cũng đỏ this bài về loại đó của vấn đề . Nhưng chiều cao GridView của tôi trong mô tả XML thiết lập như điền mẹ:
<?xml version="1.0" encoding="utf-8"?>
<GridView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/grid"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:numColumns="auto_fit"
android:horizontalSpacing="10dp"
android:verticalSpacing="10dp"
android:columnWidth="140dp"
android:gravity="center"
android:scrollbars="none"
/>
Và cuối cùng để loại bỏ tất cả những nghi ngờ, đây là mã Adaptor của tôi:
public class ImageAdapter extends BaseAdapter
{
private Activity activity;
private LayoutInflater inflater = null;
private ArrayList<Photo> photoes;
public ImageAdapter(Activity a, ArrayList<Photo> pictures)
{
photoes = pictures;
activity = a;
inflater = (LayoutInflater)activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
@Override
public View getView(int position, View convertView, ViewGroup parent)
{
Log.i("getView()", "GETTING VIEW_POSITION[" + String.valueOf(position) + "]" + (convertView != null?convertView.toString():"null"));
View mViewSlice = convertView;
if(convertView == null) {
mViewSlice = inflater.inflate(R.layout.photo_preview, null);
((TextView) mViewSlice.findViewById(R.id.name_of_photo)).setText(photoes.get(position).getName());
mViewSlice.setPadding(5, 5, 5, 5);
mViewSlice.setLayoutParams(new GridView.LayoutParams(-2, -2));
}
return mViewSlice;
}
@Override
public int getCount() {
return photoes.size();
}
@Override
public Object getItem(int position) {
return photoes.get(position);
}
@Override
public long getItemId(int position) {
return position;
}
}
Tôi hy vọng ai đó sẽ trả lời tại vấn đề của tôi và sẽ giúp tôi giải quyết nó.
Đang chờ đề xuất của bạn. Alex.
Câu hỏi của bạn là gì? –