獲取可繪製文件夾下的多個圖像並以網格視圖顯示。如何在點擊後將圖像存儲在內存中?
在網格視圖中顯示它之後,當我們點擊一個特定的圖像時,它必須存儲在設備的內部存儲器中。 我實現的代碼如下所示
public class Example3 extends AppCompatActivity {
String[] web = {"image1", "image2", "image3",
"image4", "image5", "image6", "image7",
"image8", "image9", "image10", "image11"};
Integer[] displayImages = {R.drawable.image1, R.drawable.image2, R.drawable.image3,
R.drawable.image4, R.drawable.image5, R.drawable.image6,
R.drawable.image7, R.drawable.image8, R.drawable.image9, R.drawable.image10, R.drawable.image11};
GridView gridView;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.example3);
gridView = (GridView) findViewById(R.id.gridView1);
gridView.setAdapter(new ImageAdapter(this));
gridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int position, long l) {
Toast.makeText(Example3.this, "You Clicked at " + web[+position] + " saved Successfully", Toast.LENGTH_SHORT).show();
}
});
}
private class ImageAdapter extends BaseAdapter {
Context context;
public ImageAdapter(Context context) {
this.context = context;
}
@Override
public int getCount() {
return displayImages.length;
}
@Override
public Object getItem(int position) {
return position;
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(int position, View view, ViewGroup viewGroup) {
ImageView imageView = new ImageView(this.context);
imageView.setImageResource(displayImages[position]);
imageView.setLayoutParams(new GridView.LayoutParams(180, 150));
return imageView;
}
}
}
我的問題是 - 如何存儲在內存中的特定圖像?
請詢問具體的問題,而不是一個一般的,unprecise目標 –
你到底在期待什麼,有什麼問題?你應該顯示你的代碼,以便我們可以幫助你。 – Inconnu
下一步在設備內存中存儲圖像.. –