gpt4 book ai didi

java - 在android中使用外部手机内存中的图片填充 ListView

转载 作者:太空宇宙 更新时间:2023-11-04 12:56:07 27 4
gpt4 key购买 nike

它从值中的字符串文件中获取图像,但我想指示它从手机内存中收集。有什么帮助吗?

MainActivity.java

    protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

gridView = (GridView) findViewById(R.id.gridView);
gridAdapter = new GridViewAdapter(this, R.layout.grid_item_layout, getData());
gridView.setAdapter(gridAdapter);

gridView.setOnItemClickListener(new OnItemClickListener() {

public void onItemClick(AdapterView<?> parent, View v, int position, long id) {

ImageItem item = (ImageItem) parent.getItemAtPosition(position);

//Create intent
Intent intent = new Intent(MainActivity.this, DetailsActivity.class);
intent.putExtra("title", item.getTitle());
intent.putExtra("image", item.getImage());

//Start details activity
startActivity(intent);
}
});
}
private ArrayList<ImageItem> getData() {

final ArrayList<ImageItem> imageItems = new ArrayList<>();
TypedArray imgs = getResources().obtainTypedArray(R.array.image_ids);
for (int i = 0; i < imgs.length(); i++) {
Bitmap bitmap = BitmapFactory.decodeResource(getResources(), imgs.getResourceId(i, -1));
imageItems.add(new ImageItem(bitmap, "Image#" + i));
}
return imageItems;
}

protected void onActivityResult(int requestCode, int resultCode, Intent data) {

if (requestCode == RESULT_LOAD_IMAGE && resultCode == RESULT_OK && data != null){
Uri selectedImage = data.getData();
ImageItem.setImageURI(selectedImage);

}
super.onActivityResult(requestCode, resultCode, data);
}

}

最佳答案

使用 Environment.getExternalStorageDirectory() 获取外部存储的根目录(在某些设备上是 SD 卡)。列出在您的设备上查找您的图像的所有文件

关于java - 在android中使用外部手机内存中的图片填充 ListView ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35375380/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com