Change custom title view of window at run time

Put problem concerning Views, Layouts and other XML-Resources (like AndroidManifest) here.

Change custom title view of window at run time

Postby lostInTransit » Mon May 04, 2009 3:40 pm

Hi

I am using a custom title view in my application for each activity. In one of the activities, based on button clicks I need to change the custom title view. Now this works fine every time when I make a call to setFeatureInt.

But if I try to update any items in the custom title (say change the text of a button or a text view on the title), the update does not take place.

Debugging through the code shows that the text view and button instances are not null and I can also see the custom title bar. But the text on the text view or the button is not updated. Has anyone else faced this problem?
How do I resolve it?

Thanks.
lostInTransit
Developer
Developer
 
Posts: 26
Joined: Thu Feb 12, 2009 10:37 am
Location: India

Top

Postby lostInTransit » Wed May 06, 2009 6:27 pm

Wondering if anyone knows the solution. Been 2 days :(

Please help... :cry:
lostInTransit
Developer
Developer
 
Posts: 26
Joined: Thu Feb 12, 2009 10:37 am
Location: India

Postby lostInTransit » Wed May 13, 2009 6:58 am

Still haven't gotten a reply :(
Posting the code if that helps...

Here's what I tried

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.         getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.text_title);
  2.  
  3.  
  4.  
  5.         TextView databar = (TextView) findViewById(R.id.title_text);
  6.  
  7.         databar.setText("Some Text");
  8.  
  9.         databar.postInvalidate();
  10.  
  11.  
  12.  
  13.         Button leftButton = (Button) findViewById(R.id.left_btn);
  14.  
  15.         leftButton.setOnClickListener(mLeftListener);
  16.  
  17.         leftButton.setText("Left Btn");
  18.  
  19.         leftButton.postInvalidate();
  20.  
  21.  
  22.  
  23.         Button rightBtn = (Button) findViewById(R.id.right_btn);
  24.  
  25.         rightBtn.setOnClickListener(mRightListener);
  26.  
  27.         rightBtn.postInvalidate();
Parsed in 0.032 seconds, using GeSHi 1.0.8.4
lostInTransit
Developer
Developer
 
Posts: 26
Joined: Thu Feb 12, 2009 10:37 am
Location: India

Use a LinearLayout

Postby satishkumar_lskin » Wed May 13, 2009 12:29 pm

Hi,
For ur requirement , I would suggest the following : Instead of using the Window feature Window.FEATURE_CUSTOM_TITLE , u can use a LinearLayout or a similar View as your title bar . In that case , u should have the Full Screen dimensions for ur use ( with default title bar disabled ) .
To set the Window feature , use :

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. public static void setWindowFeatures(Activity activity) {
  2.  
  3.                 // TODO Auto-generated method stub
  4.  
  5.                 activity.getWindow().setFlags(
  6.  
  7.                                 WindowManager.LayoutParams.FLAG_FULLSCREEN,
  8.  
  9.                                 WindowManager.LayoutParams.FLAG_FULLSCREEN);
  10.  
  11.                 boolean isEnabled = activity
  12.  
  13.                                 .requestWindowFeature(Window.FEATURE_NO_TITLE);
  14.  
  15. }
Parsed in 0.032 seconds, using GeSHi 1.0.8.4


To update the button text or the text of a textView , get the children of the LinearLayout that u use as title bar and update them.

Regards,
Satish
satishkumar_lskin
Developer
Developer
 
Posts: 32
Joined: Mon Oct 20, 2008 8:15 am
Location: Coimbatore , TamilNadu, India

Postby lostInTransit » Wed May 13, 2009 2:16 pm

Thanks for the suggestion satishkumar.

Actually I am using the title view through out the app to give it a uniform look and this seems the best alternative. I trust the problem is not really because of using a custom title as the title bar appears.

The thing works file the first time the title bar is changed. Even the click listeners are registered the first time (I change it as many as 3 times in the activity). But if I change it after that, neither are the listeners registered, nor is the text changed on the textview.
lostInTransit
Developer
Developer
 
Posts: 26
Joined: Thu Feb 12, 2009 10:37 am
Location: India

Postby lostInTransit » Fri May 15, 2009 1:33 pm

Thought this might help someone else

The problem is that the only Window implementation (PhoneWindow) uses a LayoutInflater in its setFeatureInt method and instantiates the new layout with inflate and attachToRoot=true. Consequently, when you call setFeatureInt, the new layouts are not replaced but attached to the internal title container and thus drawn on top of each other.

Here's what I am doing now

Let's assume we have two custom title layouts:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout android:id="@+id/custom_title_1" ...
and

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout android:id="@+id/custom_title_2" ...

and we want to replace custom_title_1 with custom_title_2, we could hide former and use setFeatureInt to add the latter:

findViewById(R.id.custom_title_1).setVisibility(View.GONE);
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.custom_title_2);
lostInTransit
Developer
Developer
 
Posts: 26
Joined: Thu Feb 12, 2009 10:37 am
Location: India

Top

Return to View, Layout & Resource Problems

Who is online

Users browsing this forum: No registered users and 4 guests