无法在索引处获得gridview子项

时间:2014-03-27 09:09:20

标签: android gridview baseadapter

我使用baseadaptergridview中添加项目,我在自定义对象的event of a listview row. Data is collected and passed to the adapter in arraylist`中执行此操作。

我就是这样做的:

  @Override
  public void onClick(View arg0) {
    List<GVShow> lstGVShow = new ArrayList<GVShow>();
    //code to construct lstGVShow here..                
                    FragmentTvGuideMain.gridView.setAdapter(new GridViewAdapter(
                            FragmentTvGuideMain.context.getApplicationContext(),
                            lstGVShow)); //FragmentTvGuideMain.context = getActivity() in Fragmentactivity

这是我的gridviewadapter

公共类GridViewAdapter扩展BaseAdapter {     私有上下文;     私人决赛名单lstGVShow;

public GridViewAdapter(Context context, List<GVShow> lstGVShow) {
    this.context = context;
    this.lstGVShow = lstGVShow;

}

public View getView(int position, View convertView, ViewGroup parent) {

    LayoutInflater inflater = (LayoutInflater) context
            .getSystemService(Context.LAYOUT_INFLATER_SERVICE);

    View gridView;

    if (convertView == null) {

        gridView = convertView;//new View(context);

        gridView = inflater.inflate(R.layout.gridview_tile_layout,parent, false);

        TextView txtShowName = (TextView) gridView.findViewById(R.id.ShowTitle);
        TextView txtShowDuration = (TextView) gridView.findViewById(R.id.ShowTime);
        ImageButton imgBtnShow = (ImageButton) gridView.findViewById(R.id.image);

        GVShow show = lstGVShow.get(position);
        txtShowName.setText(show.getShowName());
        ImageLoader.getInstance().displayImage(show.getShowImage(), imgBtnShow);

    } else {
        gridView = (View) convertView;
    }

    return gridView;
}

@Override
public int getCount() {
    return lstGVShow.size();
}

@Override
public Object getItem(int position) {
    return null;
}

@Override
public long getItemId(int position) {
    return 0;
}

}

这就是我从gridview获取孩子的方式,它提供NPE

View rlNowPlaying = FragmentTvGuideMain.gridView.getChildAt(0); //done after setting the adapter

FragmentTvGuideMain.gridView.getCount(); //returns the correct number of views added in the gridview 

在我看来,某种非阻塞调用可以在gridview的baseadapter中设置视图。我该如何解决这个问题?

0 个答案:

没有答案