0

How can i get reference to another activity, because i have placed an ActionBar in main activity say ActivityA, this ActionBar is visible on all other activities as well, now i want to access this LinearLayout and make it hidden from ActivityB.

I want to do somthing like this.

LinearLayout bar = (LinearLayout) ActivityA.findViewById(R.id.actionbarhome);
bar.setVisibility(LinearLayout.GONE);

What should be there in place of ActivityA? Any help would be appreciated.

inazaruk
  • 74,247
  • 24
  • 188
  • 156
Asif
  • 21
  • 4
  • 9

2 Answers2

2

You can inflate and grab the Layout of the ActivityA and then use findViewById to grab the Required LinearLayout e.g. :

LayoutInflater inflater = getLayoutInflater();
LinearLayout ll_ActivityA = (LinearLayout) inflater.inflate(R.layout.activity_a,null);
LinearLayout bar = (LinearLayout) ll_ActivityA.findViewById(R.id.actionbarhome);
bar.setVisibility(LinearLayout.GONE);
Khawar
  • 5,197
  • 4
  • 28
  • 52
  • second line `LinearLayout ll_ActivityA = (LinearLayout) inflater.inflate(R.layout.activity_a,null);` gives exception "source not found" – Asif Jul 14 '11 at 12:45
  • I used R.layout.activity_a as an example. You use your Layout and make sure its parent element is the same as the one on which it is being inflated. e.g. LinearLayout. – Khawar Jul 14 '11 at 13:43
1

There is a tutorial in the doc about removing the action bar for a particular activity.

Guillaume Brunerie
  • 4,676
  • 3
  • 24
  • 32
  • I need to hide LinearLayout on ActivityA from ActivityB,i have not used default ActionBar as i am using Android2.2, the ActionBar you mentioned is for android 3.0 or greater. – Asif Jul 14 '11 at 11:37
  • What ActionBar are you using then? If it’s `android.app.ActionBar` it’s only available for Android 3.0+, and I have not found any other ActionBar. If you just have a LinearLayout, I don’t see why it would be visible at all from ActivityB. – Guillaume Brunerie Jul 14 '11 at 11:47
  • actualy i have a layout file which contains home/back button, i added this layout file to TabHost in main.xml using code , In this way it behaves like ActionBar and is visible on all activities shown within TabHost. Now i need to show/hide this linearLayout. – Asif Jul 14 '11 at 12:22