gpt4 book ai didi

java - 选择位置图像不会显示在 ImageView 上

转载 作者:行者123 更新时间:2023-12-02 01:25:25 25 4
gpt4 key购买 nike

我有 1 个 int 和 1 个来自 Intent 附加的字符串,其位置我想从所选项目的位置设置 ImageView 可绘制的精确图像。代码工作并且日志显示正确的位置,但 ImageView 不会在设备中显示任何内容有ID吗?

//这是列表项的 Intent

Intent inspol = new Intent(getActivity(),Item_Click_open.class);
inspol.putExtra("IMAGE_SELECT",datassss[position]);
if (boxcolor1 == 0||boxcolor2 == 0) {
inspol.putExtra("IMAGE_TYPE",1);
}
if (boxcolor1 == 1||boxcolor2 == 1) {
inspol.putExtra("IMAGE_TYPE",2);
}
if (boxcolor1 == 2||boxcolor2 == 2) {
inspol.putExtra("IMAGE_TYPE",3);
}





new Pair<View, String>(view.findViewById(R.id.big_image),
Item_Click_open.VIEW_NAME_HEADER_IMAGE),
new Pair<View, String>(view.findViewById(R.id.big_image),
Item_Click_open.VIEW_NAME_HEADER_IMAGE2));;
ActivityCompat.startActivity(getActivity(),inspol,activityOptions.toBundle());
}
});

//Activity必须将image view设置为drawable

Intent ilm = getIntent();
sps = ilm.getStringExtra("IMAGE_SELECT");
popint = ilm.getIntExtra("IMAGE_TYPE",0);


imsec = (ImageView) findViewById(R.id.imseccc);

if (popint == 1) {
if (sps == "Beginner") {
imsec.setImageDrawable(getResources().getDrawable(R.drawable.ic_tree_bign));
}
if (sps == "Elementary") {
imsec.setImageDrawable(getResources().getDrawable(R.drawable.ic_tree_ele2));
}
if (sps == "Intermediate") {
imsec.setImageDrawable(getResources().getDrawable(R.drawable.ic_tree_inter));
}
if (sps == "Advance") {
imsec.setImageDrawable(getResources().getDrawable(R.drawable.ic_tree_advice));
}
}
if (popint == 2) {
if (sps == "Beginner") {
imsec.setImageDrawable(getResources().getDrawable(R.drawable.ic_chery));

}
if (sps == "Elementary") {
imsec.setImageDrawable(getResources().getDrawable(R.drawable.ic_limon));
}
if (sps == "Intermediate") {
imsec.setImageDrawable(getResources().getDrawable(R.drawable.ic_sbr));
}
if (sps == "Advance") {
imsec.setImageDrawable(getResources().getDrawable(R.drawable.ic_oldfood));
}
}

感谢您的帮助!

最佳答案

使用 Java 的 equals 方法来比较字符串:

if (sps.equals("Beginner") {
imsec.setImageDrawable(getResources().getDrawable(R.drawable.ic_tree_bign));
}
if (sps.equals("Elementary")) {
imsec.setImageDrawable(getResources().getDrawable(R.drawable.ic_tree_ele2));
}
if (sps.equals("Intermediate")) {
imsec.setImageDrawable(getResources().getDrawable(R.drawable.ic_tree_inter));
}
if (sps.equals("Advance")) {
imsec.setImageDrawable(getResources().getDrawable(R.drawable.ic_tree_advice));
}

关于java - 选择位置图像不会显示在 ImageView 上,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57027874/

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