GridView显示所有项目的相同屏幕

时间:2015-07-28 07:43:59

标签: android gridview

在Gridview中,当我选择一个项目时,它会转到同一页面。但是我需要根据图标名称去不同的页面(例如,点击图标CARS它应该去CARS页面有详细信息。)

这是我的java类

public class CustomAdapter extends BaseAdapter {

    String [] result;
    Context context;
    int [] imageId;
    private static LayoutInflater inflater=null;
    public CustomAdapter(MainActivity mainActivity, String[] prgmNameList, int[] prgmImages) {
        // TODO Auto-generated constructor stub
        result=prgmNameList;
        context=mainActivity;
        imageId=prgmImages;
        inflater = ( LayoutInflater )context.
                getSystemService(Context.LAYOUT_INFLATER_SERVICE);

    }

    @Override
    public int getCount() {
        // TODO Auto-generated method stub
        return result.length;
    }

    @Override
    public Object getItem(int position) {
        // TODO Auto-generated method stub
        return position;
    }

    @Override
    public long getItemId(int position) {
        // TODO Auto-generated method stub
        return position;
    }

    public class Holder
    {
        TextView tv;
        ImageView img;
    }
    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        // TODO Auto-generated method stub
        Holder holder=new Holder();
        View rowView;

        rowView = inflater.inflate(R.layout.programlist, null);
        holder.tv=(TextView) rowView.findViewById(R.id.textView1);
        holder.img=(ImageView) rowView.findViewById(R.id.imageView1);

        holder.tv.setText(result[position]);
        holder.img.setImageResource(imageId[position]);
        rowView.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                switch (position) {
                    case 1:
                        Intent intent = new Intent(context, Education.class);
                        intent.putExtra("position", position);
                        context.startActivity(intent);
                        break;
                }
                //Add the position to the intent to be used in the second activity.

            }
        });

        return rowView;
    }

}

我应该做些什么改变?

1 个答案:

答案 0 :(得分:0)

我认为你需要onItemClick和onItemClickListener。