1

我有一个动态显示数据的自定义 GridView。数据已加载,但滚动似乎不起作用。当我向下滚动gridview时,滚动条向上移动而不保留滚动位置。

以下是我的自定义 GridView 代码,

public class CustomAdapter extends BaseAdapter {

  private Context context;
  private List<PropertiesList> myList;

  public CustomAdapter(List<PropertiesList> paramList, Context paramContext)
  {
    this.myList = paramList;
    this.context = paramContext;
  }

  public int getCount()
  {
    return this.myList.size();
  }

  public Object getItem(int paramInt)
  {
    return Integer.valueOf(paramInt);
  }

  public long getItemId(int paramInt)
  {
    return paramInt;
  }

  public View getView(final int paramInt, View paramView, ViewGroup paramViewGroup)
  {

    View localView = View.inflate(this.context, R.layout.grid_content, null);
    localView.setMinimumHeight((int)(0.3D * ((WindowManager)this.context.getSystemService("window")).getDefaultDisplay().getWidth()));
    ((TextView)localView.findViewById(R.prop_type)).setText(((PropertiesList)this.myList.get(paramInt)).PropertyAddress);

    localView.findViewById(R.id.prop_type).setBackgroundResource(color.darker_gray);
    ((TextView)localView.findViewById(R.id.prop_price)).setText(((PropertiesList)this.myList.get(paramInt)).PropertyPrice);
    localView.setId(paramInt);

    ((TextView)localView.findViewById(R.id.prop_type)).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            Toast.makeText(context, "PropertyID: "+myList.get(paramInt).PropertyID, Toast.LENGTH_SHORT).show();

        }
    });


    return localView; 
  }
}

xml,

  <GridView
        android:id="@+id/camera_grid"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="top|center"
        android:columnWidth="110.0dip"
        android:gravity="center"
        android:horizontalSpacing="5.0dip"
        android:numColumns="auto_fit"
        android:orientation="vertical"
        android:scrollingCache="false"
        android:stretchMode="columnWidth"
        android:verticalSpacing="5.0dip"
        android:scrollbars="vertical" />

我的代码中有任何错误的实现吗?请帮我解决这个问题。

提前致谢!!

4

1 回答 1

0
 public Object getItem(int paramInt)
   {
     return Integer.valueOf(paramInt);
   }

此方法返回语句更改为

 mylist.get(paramInt);`
于 2013-05-27T06:27:26.017 回答