Reputation: 621
One of the items on my app is an option who leads to another activity. Ok, I can send this option to the other activity, but I must read that option and then hide some stuff from the layout based on this info.
I have added this into the onCreate method, but no succes:
Bundle extras = getIntent().getExtras();
String type = extras.getString("objects");
if(type == "animals"){
ImageView fieldSwamp = (ImageView) findViewById(R.id.btnSwamp);
((LinearLayout)fieldSwamp.getParent()).removeView(fieldSwamp);
ImageView fieldGrass = (ImageView) findViewById(R.id.btnGrass);
((LinearLayout)fieldGrass.getParent()).removeView(fieldGrass);
}
Then I tried it on the "onLocationChanged" method but no success either. I'm not sure if the problem is in the code itself or if it is where I put it. Can someone please help?
Thanks in advance!
Upvotes: 0
Views: 67
Reputation: 3357
Try
ImageView fieldSwamp = (ImageView) findViewById(R.id.btnSwamp);
fieldSwamp.setVisibility(View.GONE);
Also you should use if(type.equals(type)) {
Upvotes: 0
Reputation: 4651
try this, because .equalsIgnoreCase is better for comparing strings, and it'll ignore the letters case.
if("animals".equalsIgnoreCase(type)){
ImageView fieldSwamp = (ImageView) findViewById(R.id.btnSwamp);
((LinearLayout)fieldSwamp.getParent()).removeView(fieldSwamp);
ImageView fieldGrass = (ImageView) findViewById(R.id.btnGrass);
((LinearLayout)fieldGrass.getParent()).removeView(fieldGrass);
} else {
Log.e("type","didn't remove views.");
}
Upvotes: 1