Android 如何将图库中的图像添加到列表视图

Android 如何将图库中的图像添加到列表视图,android,android-listview,android-imageview,android-gallery,Android,Android Listview,Android Imageview,Android Gallery,我想从gallery中添加一张图片,当我按下create player时,我想将该图片添加到listview中的播放器名称旁边 现在,我的代码从drawables中获取图片,这些图片在类型化数组中访问 如何更改代码以实现从库中获取图片并在listview中显示 任何帮助都将不胜感激!谢谢 我的自定义适配器代码为: public class PlayerImageAdapter extends ArrayAdapter<Player> { private Layou

我想从gallery中添加一张图片,当我按下create player时,我想将该图片添加到listview中的播放器名称旁边

现在,我的代码从drawables中获取图片,这些图片在类型化数组中访问

如何更改代码以实现从库中获取图片并在listview中显示

任何帮助都将不胜感激!谢谢

我的自定义适配器代码为:

 public class PlayerImageAdapter extends ArrayAdapter<Player> {

        private LayoutInflater mInflater;

            private ArrayList<Player> players;
            private TypedArray mIcons;

            private int mViewResourceId;

            public PlayerImageAdapter(Context ctx, int viewResourceId,
                    ArrayList<Player> players, TypedArray icons) {
                super(ctx, viewResourceId, players);

                mInflater = (LayoutInflater)ctx.getSystemService(
                        Context.LAYOUT_INFLATER_SERVICE);

                this.players = players;
                mIcons = icons;

                mViewResourceId = viewResourceId;
            }


            @Override
            public View getView(int position, View convertView, ViewGroup parent) {
                convertView = mInflater.inflate(mViewResourceId, null);

                ImageView iv = (ImageView)convertView.findViewById(R.id.playerPic);
                iv.setImageDrawable(mIcons.getDrawable(position));

                TextView tv = (TextView)convertView.findViewById(R.id.playerName);
                tv.setText(this.players.get(position).toString());

                return convertView;
            }
        }


        //and my code that calls it:


    TypedArray icons = res.obtainTypedArray(R.array.player_pics);

                adapter = new PlayerImageAdapter(ctx, R.layout.player_customlist,
                        dataStore.getPlayers(), icons);


        My code that access the gallery is:

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

                if (requestCode == RESULT_LOAD_IMAGE && resultCode == RESULT_OK && null != data) {
                    Uri selectedImage = data.getData();
                    String[] filePathColumn = { MediaStore.Images.Media.DATA };

                    Cursor cursor = getContentResolver().query(selectedImage,
                            filePathColumn, null, null, null);
                    cursor.moveToFirst();

                    int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
                    String picturePath = cursor.getString(columnIndex);
                    cursor.close();

                    ImageView imageView = (ImageView) findViewById(R.id.imagePlayer);
                    imageView.setImageBitmap(BitmapFactory.decodeFile(picturePath));

                }


            }
公共类PlayerImageAdapter扩展了ArrayAdapter{
私人停车场;
私人ArrayList玩家;
私有型Darray mIcons;
私有int-mViewResourceId;
公共播放器图像适配器(上下文ctx,int-viewResourceId,
ArrayList播放器,键入Darray图标){
超级(ctx、viewResourceId、玩家);
mInflater=(LayoutInflater)ctx.getSystemService(
上下文。布局(充气机和服务);
这个。玩家=玩家;
mIcons=图标;
mViewResourceId=viewsourceid;
}
@凌驾
公共视图getView(int位置、视图转换视图、视图组父视图){
convertView=mInflater.inflate(mViewResourceId,null);
ImageView iv=(ImageView)convertView.findViewById(R.id.playerPic);
iv.setImageDrawable(mIcons.getDrawable(位置));
TextView tv=(TextView)convertView.findViewById(R.id.playerName);
tv.setText(this.players.get(position.toString());
返回视图;
}
}
//我的代码调用它:
TypedArray图标=res.obtainTypedArray(R.array.player_pics);
适配器=新的播放器图像适配器(ctx,R.layout.player\U自定义列表,
dataStore.getPlayers(),图标);
我访问库的代码是:
受保护的void onActivityResult(int请求代码、int结果代码、意图数据){
super.onActivityResult(请求代码、结果代码、数据);
if(requestCode==RESULT\u LOAD\u IMAGE&&resultCode==RESULT\u OK&&null!=数据){
Uri selectedImage=data.getData();
字符串[]filePathColumn={MediaStore.Images.Media.DATA};
Cursor Cursor=getContentResolver().query(selectedImage,
filePathColumn,null,null,null);
cursor.moveToFirst();
int columnIndex=cursor.getColumnIndex(filePathColumn[0]);
String picturePath=cursor.getString(columnIndex);
cursor.close();
ImageView ImageView=(ImageView)findViewById(R.id.imagePlayer);
setImageBitmap(BitmapFactory.decodeFile(picturePath));
}
}

我的代码没有问题,它可以工作。我只是想知道我将如何使用我的图库中的图像而不是drawable中的资源。只有一个图像。。。然后当我按下一个按钮时,该图像应该在列表视图中查看。你看了吗???我的代码中没有问题,它工作正常。我只是想知道我将如何使用我的图库中的图像而不是drawable中的资源。只有一个图像。。。然后当我按下一个按钮时,该图像应该在listview中查看。你看了吗???