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"
button.

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.

Thanks!
Snarky

-- 



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
"drawable"

cc.setImageResource(getContext().getResources().getIdentifier("image
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
tom-foolery?

-------------------------------------------------------------------------------------------------
TreKing < http://sites.google.com/site/rezmobileapps/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)
 http://commonsware.com  |  http://github.com/commonsguy 
 http://commonsware.com/blog  |  http://twitter.com/commonsguy 

Android Training in Oslo:  http://bit.ly/fjBo24 

-- 



Other Threads

1. Effect of copying assets in Internal memory?

I wanna store large number of images and videos on the INTERNAL
memory. I wanna know if there is some specific % size of memory that
can be used or is it upto maximum? What effect it will cause?

-- 

2. Problem uninstalling an Application package from Android device

We have an application which on start up pulls up a Terms and
Conditions screen. When the user declines these terms we have to ask
the user if he wishes to delete the package.

So, from within the application we launch the following intent:

Uri uninstallUri = Uri.parse("package:some.package.name");
Intent intent = new Intent(Intent.ACTION_DELETE, uninstallUri);
startActivity(intent);

This brings the Settings-> Manage Applications -> Uninstall page for
our application.

The user can go ahead and uninstall the pacakge. But when he chooses
not to(by pressing Cancel) he is taken to our Terms and Conditions
Activity. If he presses Back again, he is taken out of application.
The problem is that now if we pull the launcher menu, our application
icon does not show up. We can see it in the "Recently Launched
application list" and the application is still there on the device.

Is this because PackageManager disabled our application? If so, how do
we re-enable it?

What did we miss here?

Please help.

Thanks.

-- 

3. Market comments disappearing over last few days

4. internet connection on android emulator

5. dithering gradient on different devices

6. My MapActivity is not showing the map

7. getCellLocation() returns null