Same Title bar but different view below it?

by javame_android » Fri, 09 Apr 2010 22:46:25 GMT


Sponsored Links
 Hi,

In one of my Android Application I need to keep the title bar same but
the view that is shown in the rest of the screen changes. So, I have
taken different Activity for all the views that I need to show and set
the title bar in every Activities onCreate method.

Now, the problem is that I have a button in the title bar and need to
perform certain action on its click event. Writing the same event
handling code in every Activity class is very cumbersome. Is there any
other way out that whenever there is a click event on that button of
the title bar then we can have the same functionality without writing
the same code in all the Activity classes.

Can we use ViewGroup for that? I don't have much idea about ViewGroup.
Is that possible with ViewGroup?

If anyone knows the solution then please let me know.

Thanks & Regards
Sunil

--



Same Title bar but different view below it?

by Mark Murphy » Fri, 09 Apr 2010 22:48:31 GMT


 


Step #1: Create a subclass of Activity that includes your button logic

Step #2: Have your other activities subclass the class you created in
step #1

-- 
Mark Murphy (a Commons Guy)
 http://commonsware.com  |  http://twitter.com/commonsguy 

_The Busy Coder's Guide to *Advanced* Android Development_
Version 1.4 Available!

--


Sponsored Links


Same Title bar but different view below it?

by javame_android » Fri, 09 Apr 2010 22:58:06 GMT


 Hi,

Thanks for your fast response.

I am just a bit confused by what you said.

Suppose I have a Class A that has my button logic, then according to
what I understood I need to

1. Create a subclass of A such as Class B extends A

2. Other activities subclass B such as Class C extends B

If that's correct then why can't Class C directly extends A such as
Class C extends A

Please correct me if I am wrong.


Thanks & Regards
Sunil

--



Same Title bar but different view below it?

by javame_android » Fri, 09 Apr 2010 23:03:07 GMT


 Hi,

One more thing then when I need to display this subclasses, will they
be displayed as we normally display one activity from another activity
i.e. startActivity(intentObj).

Please reply if anyone knows the solutions.


Thanks & regards
Sunil

--



Same Title bar but different view below it?

by javame_android » Fri, 09 Apr 2010 23:50:54 GMT


 Hi,

I have been able to extend the class and get the button click event in
the same Activity.

But now there is another issue. I want to display images in Gallery
from that button click but its not happening so if I click on that
button from another activity. The onclick method is being called but
its not changing the view to Gallery. If I click on that button from
the main Activity in which there is the button logic then the Gallery
view is being displayed.

Can anyone let me know what is the problem?


Thanks & regards
Sunil

--



Other Threads

1. App download/install count - market glitch?

I have couple of apps (billboard100 and xmplayer) that had been
reaching download/installs of 10k/9k+ and 9k/6k respectively. This
morning the counts dropped to 1k/1k and 5k/3k. How is that possible?
My ad clicks suggests otherwise.

Anybody experienced the same?

Ken

-- 

2. Help me out with my Listview custom row layout, I already tried many combinations

Hi,
I am having trouble getting my layout to give me result I need, I
already tried many options and it seems that I'm doing something wrong
or completely missing something.

I have a listview with a custom row layout I can't seem to working
although it shouldn't be complex.
I need of the list row to insist of:

Icon --  title text (bigger and bold) with a short multi line text
under the title -- ImageButton

My problem in most of my tests is the icon to the right usually
doesn't appear, I guess my center group grows and takes all the space
of the button.
My last failed attempt was with a Relative Layout, didn't have too
much luck with a Linear Layout either.

Here is the row XML:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/
android"
     android:layout_width="fill_parent"
     android:layout_height="wrap_content"
     android:padding="4dip">
    <ImageView
        android:id="@+id/icon"
        android:layout_width="48dip"
        android:layout_height="48dip"
        android:src="@drawable/icon"
        android:layout_marginRight="4dip"
        />

  <LinearLayout
         android:id="@+id/centertext"
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"
     android:layout_toRightOf="@+id/icon"
     android:orientation="vertical"
         >
        <TextView
            android:id="@+id/titletext"
            android:textSize="16sp"
            android:textStyle="bold"
            android:textColor="@color/titlecolor"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"

            />
        <TextView
                android:id="@+id/summarytext"
            android:layout_width="fill_parent"
                android:layout_height="fill_parent"
            android:textSize="10sp"
            android:textColor="@color/titlecolor"
            android:singleLine="false"

        />
    </LinearLayout>

    <ImageButton
    android:id="@+id/android_button"
    android:layout_width="48dip"
    android:layout_height="48dip"
    android:layout_toRightOf="@+id/centertext"
    android:src="@drawable/playbutton"
    android:background="#00000000"
        />

</RelativeLayout>


Any pointers on what am I doing wrong ?  Would you suggest keeping the
relative view or dropping it ?

How can I force my vertical LinearLayout (@+id/centertext) to leave
space for my button ? I tried both 'wrap_content' and 'fill_parent'

-- 

3. How To: ListActivity (Same as ViewContactDetails.java of "Contacts" in android emulator)

4. need help on how to access sms programmatically

5. Does Droid phone have a defect on message service?

6. Can't sign my apk after updating sdk 2.2 (and the adt plugin)

7. how to open an App when the Android OS start up