我有一个图像的网格视图。选择一个图像,它进入下一个活动并获得显示。我想显示一些textview。如何做到这一点?

时间:2015-10-08 10:04:45

标签: android gridview

我不想在网格视图中显示任何文字。选择图像后,它将显示详细信息。

选择图像时,我想用它显示详细信息

我的图像适配器类

public class ImageAdapter extends BaseAdapter {
private Context mContext;

public ImageAdapter(Context c) {
    mContext = c;
}

public int getCount() {
    return mThumbIds.length;
}

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

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

// Create a new ImageView for each item referenced by the Adapter
public View getView(int position, View convertView, ViewGroup parent) {
    ImageView imageView;
    // if it's not recycled, initialize some attributes
    if (convertView == null) { 
        imageView = new ImageView(mContext);
        // Center crop image
        imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
    } else {
        imageView = (ImageView) convertView;
    }
    // Set images into ImageView
    imageView.setImageResource(mThumbIds[position]);
    return imageView;
}

// References to our images in res > drawable
public Integer[] mThumbIds = { R.drawable.sample_0, R.drawable.sample_1,
        R.drawable.sample_2, R.drawable.sample_3, R.drawable.sample_9,
        R.drawable.sample_5, R.drawable.sample_6, R.drawable.sample_7,
        R.drawable.sample_8, R.drawable.sample_9, R.drawable.sample_10,
        R.drawable.sample_11, R.drawable.sample_12, R.drawable.sample_13,
        R.drawable.sample_14, R.drawable.sample_15, R.drawable.sample_16,
        R.drawable.sample_17, R.drawable.sample_18 };

我的SingleitemView类

      public class SingleItemView extends Activity {

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    // Get the view from singleitemview.xml
    setContentView(R.layout.singleitemview);

    // Get position from intent passed from MainActivity.java
    Intent i = getIntent();

    int position = i.getExtras().getInt("id");

    // Open the Image adapter
    ImageAdapter imageAdapter = new ImageAdapter(this);

    // Locate the ImageView in singleitemview.xml
    ImageView imageView = (ImageView) findViewById(R.id.image);

    // Get image and position from ImageAdapter.java and set into ImageView
    imageView.setImageResource(imageAdapter.mThumbIds[position]);
}

0 个答案:

没有答案