gpt4 book ai didi

android - 获取 GridView 项目的图像名称

转载 作者:行者123 更新时间:2023-11-29 16:10:15 26 4
gpt4 key购买 nike

我有一个 gridview,我正在对话框 View 中对其进行扩充。现在,当我打开对话框(使用 GridView )时,它会显示一组 10 张图像。

当关闭对话框时,我选择的图像将设置在 ImageView 上。

现在我的问题是我能得到图像的名称吗??这是在 ImageView 上设置的???

我必须把它保存在某个地方。

@Override
public void onClick(View view) {
// TODO Auto-generated method stub
final Dialog groupIconsDialog = new Dialog(CreateGroupActivity.this);
groupIconsDialog.setTitle("Choose Group Icon");
groupIconsDialog.setContentView(R.layout.group_icons_layout);
//calling and setting the image icons to the grid view adapter
GridView groupIconsGrid = (GridView)groupIconsDialog.findViewById(R.id.grid_groupIcons);
groupIconsGrid.setAdapter(new GroupIconAdapter(CreateGroupActivity.this));

groupIconsGrid.setOnItemClickListener(new OnItemClickListener() {

@Override
public void onItemClick(AdapterView<?> arg0, View arg1,
int position, long arg3) {
// TODO Auto-generated method stub

group_icon.setImageResource(new GroupIconAdapter(CreateGroupActivity.this).mThumbIds[position]);
groupIconsDialog.dismiss();

}

});

groupIconsDialog.show();

}
});

图像适配器

public class GroupIconAdapter extends BaseAdapter {

private Context mContext;

//icons image array
public Integer[] mThumbIds = {
R.drawable.mogra,R.drawable.rhino,
R.drawable.zebra,R.drawable.lion,
R.drawable.mogra,R.drawable.rhino,
R.drawable.giraffee,R.drawable.giraffee,
R.drawable.lion,R.drawable.rhino
};

public GroupIconAdapter(Context c) {
// TODO Auto-generated constructor stub
mContext = c;
}

@Override
public int getCount() {
// TODO Auto-generated method stub
return mThumbIds.length;
}

@Override
public Object getItem(int position) {
// TODO Auto-generated method stub
return mThumbIds[position];
}

@Override
public long getItemId(int arg0) {
// TODO Auto-generated method stub
return 0;
}

@Override
public View getView(int position, View view, ViewGroup parent) {
// TODO Auto-generated method stub
ImageView imageView = new ImageView(mContext);
imageView.setImageResource(mThumbIds[position]);
imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
imageView.setLayoutParams(new GridView.LayoutParams(50, 50));
return imageView;
}
}

最佳答案

是的,如果您有图像的资源 ID,您可以获得图像的名称。您可以使用 getResourceEntryName(resourceId)

String name = getResources().getResourceEntryName(mThumbIds[position]);

关于android - 获取 GridView 项目的图像名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14054316/

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