現在、いくつかのサムネイルを表示している作業グリッドビューがあります。現在、画像を選択すると、画像のより大きな解像度が壁紙として保存されます。前のアクティビティからのGridview選択に基づいて画像を表示
私がしたいことは、新しいインテントを開いて、クリックしたGridViewの位置に基づいてフル解像度の画像を表示することです。私はどのように新しい活動/意図からどの位置がクリックされたのかわかりません。
相続人は、私は私の主な活動に持っているもの
public class test extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
GridView gridview = (GridView) findViewById(R.id.gridview);
gridview.setAdapter(new ImageAdapter(getApplicationContext()));
gridview.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
Toast.makeText(test.this, "" + position + "" + id, Toast.LENGTH_SHORT).show();
//Make a Bitmap from the Resource
ImageAdapter i = (ImageAdapter)parent.getAdapter();
Bitmap mBitmap = BitmapFactory.decodeResource(getResources(),(int)i.getItemId(position));
//Get the WallpaperManager
WallpaperManager myWallpaperManager = WallpaperManager.getInstance(getApplicationContext());
try {
//Set the clicked bitmap
myWallpaperManager.setBitmap(mBitmap);
Toast.makeText(test.this, "Wallpaper set", Toast.LENGTH_SHORT).show();
} catch (IOException e) {
Toast.makeText(test.this, "Error setting wallpaper", Toast.LENGTH_SHORT).show();
}
}
});
}
}
ImageAdapter
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 mFullSizeIds[position];
}
// create a new ImageView for each item referenced by the Adapter
public View getView(int position, View convertView, ViewGroup parent) {
ImageView imageView;
if (convertView == null) { // if it's not recycled, initialize some attributes
imageView = new ImageView(mContext);
imageView.setLayoutParams(new GridView.LayoutParams(85, 85));
imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
imageView.setPadding(8, 8, 8, 8);
} else {
imageView = (ImageView) convertView;
}
imageView.setImageResource(mThumbIds[position]);
return imageView;
}
// references to our images
private Integer[] mThumbIds = {
R.drawable.sample_1, R.drawable.sample_2,
R.drawable.sample_3, R.drawable.sample_4,
R.drawable.sample_5, R.drawable.sample_6,
R.drawable.sample_7
};
private Integer[] mFullSizeIds = {
R.drawable.wallpaper1,
R.drawable.wallpaper2,
R.drawable.wallpaper3,
R.drawable.wallpaper4,
R.drawable.wallpaper5,
R.drawable.wallpaper6,
R.drawable.wallpaper7
};
}
とブランクFullViewテンプレート
public class FullView extends Activity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.fullview);
ImageView imageview;
imageview.setImageResource(mFullSizeIds[**]) <--- How to set ** to what GridView position was selected?
}
}
私は本当ににより、この新しい活動でのGridViewからクリックされた位置に合格する方法を知らないことにはまだFullView活動には何も書いていません。
(私は私の主な活動で意思のコードを書いていないのいずれかのようにあなたはそれが現在どのように動作するかを見ることができます)
どのように私は新しい活動に選ばれたGridViewの位置を通過していますか?
完璧、ありがとうございます。 – jblz