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. How to access the phone contacts in latest version of android 2.1

Hi guys,
           I need some help on the issue "How to access the phone
contacts in latest version of android 2.1". I need need the code
example for for accessing name and number of the contacts ....

Thanks in advance
Manoj C


2. Pause Within a loop

I have a loop which draw a bitmap
for(int i=0;i<10;i++){
    //here I draw a bitmap which will move to right a little bit in
each loop
    //I want a pause here so that an animation can be made


3. Why does addHeaderView make a ListActivity forgetful of its position ?

4. How to do animation when click on a bitmap

5. Send key event using native methods or low level classes -- possible solutions ??

6. chatting IRC yuuukk...

7. Mirink