Android:如何从GridView中提取数据?

时间:2011-04-08 09:23:21

标签: android

大家好 我有一个由图像和textview组成的FrameLayout GridView。我想在单击Grid的单元格时获取相应的图像和文本。提到textview是图像的顶部。

有人知道怎么做吗?

2 个答案:

答案 0 :(得分:1)

第一个注册项单击网格视图的监听器 例如gridview.setOnItemClickListener(gridItemClickListener);

然后

   OnItemClickListener gridItemClickListener = new OnItemClickListner() 
    {
   public void onItemClick(AdapterView<?> parent, View view, int position, long id)

   {

      // here you will get your clicked cell of grid and you can find the image and text.
      ImageView image = view.findViewById(R.id.grid_raw_image);
      TextView textView = view.findViewById(R.id.grid_raw_text);  
   }
};

答案 1 :(得分:0)

如果您使用google建议的viewHolder技术,请使用:

gridView.setOnItemClickListener(new OnItemClickListner()
  {
  @Override
  public void onItemClick(AdapterView<?> parent, View view, int position, long id)
    {
    ViewHolder holder=(ViewHolder)view.getTag();
    //use the views you hold in the viewHolder
    ...
    }
  });