Finding the ID of the current layout

by Snarky » Tue, 15 Mar 2011 05:04:57 GMT

Sponsored Links
 I'm sure this is far simpler than I'm making it out to be, but I'm
having trouble figuring out how to retrieve the ID of the current
view, so that I can conditionally alter the behavior of the "Back"

Here's the scenario...I have four layouts that I'm using:
- Main
- Preferences
- Transaction List
- Transaction Details

Depending on the layout that's current, I want the Back button to
either take the user back to the Main layout (Prefs and T-List), or
back to the Transaction List (T-Details).

But, for the life of me, I can't figure out how to retrieve the
current layout's ID to use as fodder for the switch.

I'm far from a seasoned programmer, and this is a hobby project, but
it's been bugging me for a few days now, and I thought someone here
might have a suggestion.



Re: Finding the ID of the current layout

by lbendlin » Tue, 15 Mar 2011 05:09:32 GMT

 here's how I identify image resources by name. You should be able to
do something similar for views. Just use "layout" rather than

name", "drawable", getContext().getPackageName()));


Sponsored Links

Re: Finding the ID of the current layout

by TreKing » Tue, 15 Mar 2011 05:11:39 GMT


Why not use two activities and let the system do it's thing (automatically
taking you back where you came from) instead of this conditional

TreKing <> ; - Chicago
transit tracking app for Android-powered devices


Re: Finding the ID of the current layout

by Brill Pappin » Tue, 15 Mar 2011 06:32:13 GMT

 I had to do this recently.
There is apparently not an easy way to get the resource id of the layout 
your view was just created from, however I used the tag attribute to sort 
out which was which.

<... layout android:tag="view1">
</ ... layout>

in your view you can get getTag().

- Brill Pappin


Re: Finding the ID of the current layout

by Mark Murphy » Tue, 15 Mar 2011 06:35:13 GMT


Or, hang tight for a bit, and you can use fragments and the
FragmentManager, if some of these things might be on the screen at the
same time. The "hang tight" is just a matter of the community wrapping
its collective head around fragments and the new Android Compatibility
Library (with the painful acronym of ACL).

Mark Murphy (a Commons Guy)  |  | 

Android Training in Oslo: 


Other Threads

1. Booting the target with boot.img generated by Android

Hello All,

I am working with Android on a custom PXA310 based platform.  I am
facing issues while launching the Linux kernel and Android from
boot.img that is generated as part of Android build.  I have
summarized two scenarios below.


I am attempting to use boot.img built by Android to launch the Linux
kernel and Android

* Build the Linux kernel to generate arch/arm/boot/zImage
* The kernel has been built with
          ->CONFIG_CMDLINE set to onsole=ttyS0,38400 mem=128M* Copy the Linux kernel into Android sources under vendor/hw/platform/kernel
* Ensure that ARGET_NO_KERNELis set to false in
* Build Android.  This generates boot.img and recovery.img with the
prebuilt kernel
* Program boot.img, recovery.img to NAND flash on target platform
* On booting, Bootloader finds the default boot kernel or recovery
kernel (depending on the command in BCB)
* However, kernel boot fails while attempting to find a root file system (RFS)
* This is because the Linux kernel has no knowledge of where RFS
exists (we need to pass oot=option at kernel boot time? Or is it
some kernel config setting??)

I don't use the boot.img with this scenario.  In this scenario, I am
building Android's ramdisk (the contents of ramdisk.img) statically
with the Linux kernel.

* Build Android.  Copy the contents of ramdisk.img (from Android
folder out/target/hw/platform/root) to kernel sources to a folder
named 'root'
* Build the Linux kernel to generate arch/arm/boot/zImage
* The kernel has been built with
       -> CONFIG_BLK_DEV_INITRD=y and CONFIG_INITRAMFS_SOURCE=oot       -> CONFIG_CMDLINE is set to onsole=ttyS0,38400 mem=128M* Program this Linux kernel to NAND Flash on target platform
* On booting:
* Bootloader launches this kernel
        -> mounts the ramdisk provided as INITRAMFS, runs Android init
        -> mounts system.img and userdata.img programmed in NAND flash
        -> launches Android

Versions of Software being used are as follows:
Linux Kernel - Sources based on linux-2.6.28
Android - Sources based on Android source with tag 'android-sdk-1.5_r1'

On going through the build logs for Kernel and Android, I have
determined that the way boot.img is built is different from the way
the Linux kernel builds the kernel binary with CONFIG_INITRAMFS_SOURCE
set to point to a RAM disk.

Has anyone got the boot.img to launch the kernel and Android
successfully?  Any pointers on where I need to look or what parameters
I need to pass to the kernel to mount the ramdisk while using boot.img
would be extremely helpful.

Thank you for your time.



2. Mobile offline gmail web app on Android does not work for me!

Been looking at the mobile gmail offline/html5 web app demos from
earlier this year.

Supposedly you should be able to compose an email whilst offline and
it will be saved to an Outbox folder.

However, I don't seem to be able to get this work in any of the
1.5 emulator
1.6 emulator
my Canadian Rogers HTC Magic 1.5

I tried creating an email then before I click Send, I put the Android
into Airplane mode.
But it just hangs and then eventually comes back with an "Oops!" error
saying "This is taking longer than usual.  Please check that you have
a working network connection and try again"

Anyone else managed to get this to work?

3. Tanya Bluetooth

4. How to call built-in camera application from my app??

5. Using android:configChanges to handle orientation

6. what exactly there is in apk file??

7. Debugging on Live device