Select 位置图像不会显示在 ImageView 上
Select postion image won't show on ImageView
我有 1 个 int 和 1 个字符串来自 intent extras 我想设置图像视图可绘制来自所选项目位置的精确图像。代码有效,日志显示正确位置,但图像视图不会在设备中显示任何内容
有 ID 吗?
// 这是来自列表项的意图
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));
}
}
感谢您的帮助!
试试这个:
final String sps = ilm.getStringExtra("IMAGE_SELECT");
int popint = ilm.getIntExtra("IMAGE_TYPE", 0);
if (popint == 1) {
switch (sps.toLowerCase()){
case "beginner":
imsec.setImageDrawable(ContextCompat.getDrawable(Item_Click_open.this, R.drawable.ic_tree_bign));
break;
case "elementary":
imsec.setImageDrawable(ContextCompat.getDrawable(Item_Click_open.this, R.drawable.ic_tree_ele2));
break;
case "intermediate":
imsec.setImageDrawable(ContextCompat.getDrawable(Item_Click_open.this, R.drawable.ic_tree_inter));
break;
case "advance":
imsec.setImageDrawable(ContextCompat.getDrawable(Item_Click_open.this, R.drawable.ic_tree_advice));
break;
}
} else if (popint == 2){
switch (sps.toLowerCase()){
case "beginner":
imsec.setImageDrawable(ContextCompat.getDrawable(Item_Click_open.this, R.drawable.ic_chery));
break;
case "elementary":
imsec.setImageDrawable(ContextCompat.getDrawable(Item_Click_open.this, R.drawable.ic_limon));
break;
case "intermediate":
imsec.setImageDrawable(ContextCompat.getDrawable(Item_Click_open.this, R.drawable.ic_sbr));
break;
case "advance":
imsec.setImageDrawable(ContextCompat.getDrawable(Item_Click_open.this, R.drawable.ic_oldfood));
break;
}
}
使用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));
}
我有 1 个 int 和 1 个字符串来自 intent extras 我想设置图像视图可绘制来自所选项目位置的精确图像。代码有效,日志显示正确位置,但图像视图不会在设备中显示任何内容 有 ID 吗?
// 这是来自列表项的意图
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));
}
}
感谢您的帮助!
试试这个:
final String sps = ilm.getStringExtra("IMAGE_SELECT");
int popint = ilm.getIntExtra("IMAGE_TYPE", 0);
if (popint == 1) {
switch (sps.toLowerCase()){
case "beginner":
imsec.setImageDrawable(ContextCompat.getDrawable(Item_Click_open.this, R.drawable.ic_tree_bign));
break;
case "elementary":
imsec.setImageDrawable(ContextCompat.getDrawable(Item_Click_open.this, R.drawable.ic_tree_ele2));
break;
case "intermediate":
imsec.setImageDrawable(ContextCompat.getDrawable(Item_Click_open.this, R.drawable.ic_tree_inter));
break;
case "advance":
imsec.setImageDrawable(ContextCompat.getDrawable(Item_Click_open.this, R.drawable.ic_tree_advice));
break;
}
} else if (popint == 2){
switch (sps.toLowerCase()){
case "beginner":
imsec.setImageDrawable(ContextCompat.getDrawable(Item_Click_open.this, R.drawable.ic_chery));
break;
case "elementary":
imsec.setImageDrawable(ContextCompat.getDrawable(Item_Click_open.this, R.drawable.ic_limon));
break;
case "intermediate":
imsec.setImageDrawable(ContextCompat.getDrawable(Item_Click_open.this, R.drawable.ic_sbr));
break;
case "advance":
imsec.setImageDrawable(ContextCompat.getDrawable(Item_Click_open.this, R.drawable.ic_oldfood));
break;
}
}
使用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));
}