ImageButton doesnt work when I change the visibility to visible. The only visible thing is something like a small shadow (which works like a imagebutton) but the image doesnt show up. All images are added to the project.
main activity:
Button search;
EditText searchLocation;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
search = findViewById(R.id.buttonSearchAll);
searchLocation = findViewById(R.id.editLocation);
search.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String str = searchLocation.getText().toString().trim();
Intent intent = new Intent(getApplicationContext(), MainActivity2.class);
intent.putExtra("message", str);
startActivity(intent);
}
});
}
main activity2:
TextView noResults, searched;
ImageButton btHotel1, btHotel2;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main2);
btHotel1 = findViewById(R.id.btHotel1);
btHotel1.setVisibility(View.GONE);
btHotel2 = findViewById(R.id.btHotel2);
btHotel2.setVisibility(View.GONE);
noResults = findViewById(R.id.tvNoResults);
btHotel1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
startActivity(new Intent(MainActivity2.this, MainActivity3.class));
}
});
btHotel2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
startActivity(new Intent(MainActivity2.this, MainActivity3.class));
}
});
Intent intent = getIntent();
String str = intent.getStringExtra("message");
searched.setText(str);
if (str.equalsIgnoreCase("vienna")){
btHotel2.setVisibility(View.VISIBLE); //but there's only a small shadow
return;
}
noResults.setVisibility(View.VISIBLE);
}
}
Im not sure why it doesnt work.
question from:
https://stackoverflow.com/questions/65852446/imagebutton-doesnt-work-android-studio-java 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…