Hello SDK developers

I finally did get a reply for the problem below and I am being told
this

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.

You can workaround this by using the a helper method instead of
setFeatureInt. The helper simply removes all views from the internal
title container before the new custom title feature is set



I did not find this documented in any of the javadocs or in any
references. Is setFeatureInt intended to behave like this?

This is the method I am using in order to remove all views from the
title. It works fine. Can anyone please confirm if this is the correct
way to remove views from the title or an undesirable hack likely to
change in the future updates. Thanks a lot.

private void setCustomTitle(int value) {
    try {
        // retrieve value for
com.android.internal.R.id.title_container
        int titleContainerId = (Integer) Class.forName(
                "com.android.internal.R$id").getField
("title_container").get(null);

        // remove all views from titleContainer
        ((ViewGroup) getWindow().findViewById
(titleContainerId)).removeAllViews();

        // add new custom title view
        getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, value);

    } catch(Exception ex) {}
}

On May 14, 9:35 pm, idev <ideveloper...@gmail.com> wrote:
> This is what the whole thing looks like. The first time I settitle,
> it works fine (in onCreate). The next time I set it, it works fine (in
> searchHandler). The third time when I do it (in reloadHandler), the
> click listeners are not registered and the text in the text view does
> not change.
>
> I had initially put the code outside handlers in the click listeners.
> But that didn;t work either. Also tried calling invalidate() on the
> buttons and textview. But that didn't help either.
>
> Thanks.
>
> @Override
> public void onCreate(Bundle savedInstanceState) {
>         super.onCreate(savedInstanceState);
>         requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
>
>         getWindow().setFeatureInt
> (Window.FEATURE_CUSTOM_TITLE,R.layout.text_title);
>
>         TextView databar = (TextView) findViewById(R.id.search_title_text);
>         databar.setText("My Text");
>
>         // Watch for button clicks.
>         Button applyButton = (Button) findViewById(R.id.srch_left_btn);
>         applyButton.setOnClickListener(mOtherButtonListener);
>         applyButton.setText("Some Text");
>
>         Button searchBtn = (Button) findViewById(R.id.srch_right_btn);
>         searchBtn.setOnClickListener(searchListener);
>
> }
>
> OnClickListener mOtherButtonListener = new OnClickListener() {
>         public void onClick(View v) {
>                 finish();
>         }
>
> };
>
> OnClickListener searchListener = new Button.OnClickListener() {
>         public void onClick(View v) {
>                 searchHandler.sendEmptyMessage(1);
>         }
>
> };
>
> Handler searchHandler = new Handler() {
>
>         @Override
>         public void handleMessage(Message message) {
>                 MyClass.this.getWindow().setFeatureInt
> (Window.FEATURE_CUSTOM_TITLE,R.layout.search_title);
>
>                 final EditText fullSearchField = (EditText) findViewById
> (R.id.title_full_search);
>
>                 fullSearchField.setOnKeyListener(new OnKeyListener() {
>                         public boolean onKey(View v, int keyCode, KeyEvent 
> event) {
>                                 if ((event.getAction() == 
> KeyEvent.ACTION_DOWN)
>                                                 && (keyCode == 
> KeyEvent.KEYCODE_ENTER)) {
>
>                                         String searchTxt = 
> fullSearchField.getText().toString();
>                                         getSearchResults(searchTxt);
>                                         return true;
>                                 }
>                                 return false;
>                         }
>                 });
>
>                 Button cancelBtn = (Button) MyClass.this.findViewById
> (R.id.title_cancel_btn);
>                 cancelBtn.setOnClickListener(cancelSearchListener);
>         }
>
> };
>
> OnClickListener cancelSearchListener = new OnClickListener() {
>         public void onClick(View v) {
>                 reloadHandler.sendEmptyMessage(1);
>         }
>
> };
>
> Handler reloadHandler = new Handler() {
>
>         @Override
>         public void handleMessage(Message message) {
>                 MyClass.this.getWindow().setFeatureInt
> (Window.FEATURE_CUSTOM_TITLE,R.layout.text_title);
>
>                 TextView databar = (TextView) MyClass.this.findViewById
> (R.id.search_title_text);
>                 databar.setText("My Text");
>
>                 Button applyButton = (Button) MyClass.this.findViewById
> (R.id.srch_left_btn);
>                 applyButton.setText("Some Text");
>                 applyButton.setOnClickListener(mOtherButtonListener);
>
>                 Button searchBtn = (Button) MyClass.this.findViewById
> (R.id.srch_right_btn);
>                 searchBtn.setOnClickListener(searchListener);
>
>                 MyClass.this.reloadOldData();
>         }
>
> };
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers-unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to