AndroidBar Tab on Fragments/EU4You_6 - android

How are you Mark? I have a question regarding the program you have written in the book "CommonsWare The Busy Coders Guide to Android Development".
I am talking about Fragments/EU4You_6 on Chapter 28 page 377. I want to expand this by adding an ActionBar Tab.
Without making any changes on your original program, what I did was that I copied EU4You.java to EU5You.java, which represents Tab2. EU4You.java will be the default Tab1.
The following are my approach:
I created a java program called EU4Main.java, which represents the MAIN program instead of the original EU4You. Of course, I changed the manifest to android:name=".EU4Main"
The EU4Main.java is where I put the ActionBar Tab. The trouble is and making me frustrated is in the TabListener setup. I have this setup .setTabListener(new TabListener(EU4You.class))); , which passes a Class. It did not work. Do you have any advise on this instead of passing a class?
Also, the onTabSelected on the code snippets below, did not work properly. If I clicked Tab2, it will show the list for Tab2 but it will automatically returns to Tab1. It won't stay at Tab2. I don't know why?
I would appreciate of any help if you can provide a better and working approach for both .setTabListener and onTabSelected
I have also extended FragmentActivity to EU4Main or shall I just use extends Activity instead?
Thanks in advance.
I have included EU4Main below with incorrect and incomplete codes( I just can't make it work...)
public class EU4Main extends FragmentActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
final ActionBar bar = getActionBar();
bar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
bar.setDisplayOptions(0, ActionBar.DISPLAY_SHOW_TITLE);
bar.addTab(bar
.newTab()
.setText("Countries")
.setTabListener(new TabListener(EU4You.class)));
bar.addTab(bar
.newTab()
.setText("Artists")
.setTabListener(new TabListener(EU5You.class)));
.
.
.
private class TabListener implements ActionBar.TabListener {
public TabListener(Activity activity) {
mActivity = activity;
}
public void onTabSelected(ActionBar.Tab tab, android.app.FragmentTransaction unused) {
if (tab.getPosition() == 0) {
Intent intent = new Intent();
String packageName = "com.commonsware.android.eu4you";
String className = "com.commonsware.android.eu4you.EU4You";
intent.setClassName(packageName, className);
startActivity(intent);
else{
Intent intent = new Intent();
String packageName = "com.commonsware.android.eu4you";
String className = "com.commonsware.android.eu4you.EU5You";
intent.setClassName(packageName, className);
startActivity(intent);
}
}
public void onTabUnselected(ActionBar.Tab tab, android.app.FragmentTransaction unused) {
FragmentManager fragMgr = getSupportFragmentManager();
FragmentTransaction xaction=fragMgr.beginTransaction();
}
public void onTabReselected(ActionBar.Tab tab,
android.app.FragmentTransaction xaction) {
// NO-OP
}
}

Your TabListener has a constructor that takes an Activity. You are calling the constructor with a Class. A Class is not an Activity.
Furthermore, you are using two separate TabListener instances, but your code for TabListener does not do anything different based upon the supplied parameter.
And, you are starting activities when tabs are selected, which is not going to be especially useful.
When a TabListener is called with onTabSelected(), it needs to affect a change to the existing UI. Starting a whole new activity does not constitute a change to the existing UI. Rather, TabListener should do something like:
execute a FragmentTransaction
set a fresh ListAdapter in the ListFragment managed by the tabs
update ordinary widgets in the current activity
etc.

Related

How to refresh the content of a tab in an actionBar (Android)?

Here the summary of my 'project' on Android 4.x and the problem I can't solve:
i have an actionBar with 2 tabs (i know it is deprecated):
...
Fragment fragmentTab1 = new FragmentTab1();
Fragment fragmentTab2 = new FragmentTab2();
Fragment fragmentTab3 = new FragmentTab3();
ActionBar.Tab tab1, tab2;
ActionBar actionBar = getActionBar();
tab1 = actionBar.newTab().setText("tab1");
tab2 = actionBar.newTab().setText("tab2");
tab1.setTabListener(new MyTabListener(fragmentTab1));
tab2.setTabListener(new MyTabListener(fragmentTab2));
actionBar.addTab(tab1);
actionBar.addTab(tab2);
...
I would like to change the fragment of a tab and refresh what the user sees, doing that in a method (not only when the tab is (re)selected).
It sounds simple, but impossible to find a easy way to do that.
After many fails, this is what I try (i remove the tab and add it with a new fragment):
void myMethod () {
getActionBar().removeTabAt(0);
tab1 = actionBar.newTab().setText("tab3");
tab1.setTabListener(new MyTabListener(fragmentTab3));
getActionBar().addTab(tab1, 0);
...
And then this awful thing to desesperatly try to update what is seen...
...
getActionBar().setSelectedNavigationItem(tab1.getPosition()+1);
getActionBar().setSelectedNavigationItem(tab1.getPosition());
}
Everything goes as wanted, except that the reselected tab1 is empty... :(
If I select with my finger tab2 then tab1 (so manually in place of programmaticaly), then tab1 appears as wanted...
So, how can I change programmaticaly the content of a tab and refresh what is seen in an actionBar?
Already a big thanks for your time!
You should depend on TabListener methods, don't do getActionBar().setSelectedNavigationItem(). There are good code samples on the Internet.
1) Google webpage # Creating Swipe Views with Tabs. Code snippet:
ActionBar.TabListener tabListener = new ActionBar.TabListener() {
public void onTabSelected(ActionBar.Tab tab, FragmentTransaction ft) {
// show the given tab
}
public void onTabUnselected(ActionBar.Tab tab, FragmentTransaction ft) {
// hide the given tab
}
public void onTabReselected(ActionBar.Tab tab, FragmentTransaction ft) {
// probably ignore this event
}
};
Notes: Refresh your data in onTabSelected(). You may check for tags or text in tab parameter.
2) Another good link for you # Android Fragment Tabs Example. Code snippet from the link:
public class TabListener implements ActionBar.TabListener {
private Fragment fragment;
public TabListener(Fragment fragment) {
this.fragment = fragment;
}
// When a tab is tapped, the FragmentTransaction replaces
// the content of our main layout with the specified fragment;
// that's why we declared an id for the main layout.
#Override
public void onTabSelected(Tab tab, FragmentTransaction ft) {
ft.replace(R.id.activity_main, fragment);
}
Notes: Again, refresh your data in onTabSelected(). I have to warn you that TabListener is deprecated in the new Lollipop API.
EDIT:
Sample code to set Tabs to the correct Fragments.
// Setting tab listeners.
bmwTab.setTabListener(new TabListener(bmwFragmentTab));
toyotaTab.setTabListener(new TabListener(toyotaFragmentTab));
fordTab.setTabListener(new TabListener(fordFragmentTab));
Good luck and have fun...

How to update my fragment?

I'm passing data from fragment to another fragment with a bundle, but I have a map and I want to update this fragment and non replace it...this is the code in the MainActivity:
Mapped map = new Mapped();
final Bundle bundle = new Bundle();
bundle.putString("Position",one);
bundle.putString("ID",two);
map.setArguments(bundle);
getSupportFragmentManager().beginTransaction().replace(R.id.mapView, map).commit();
and every time it delete the old fragment...How can I do to update it and not replace?
EDIT: this is the code of MainActivity:
public class MainActivity extends FragmentActivity implements Connection.SendMessage
{
ViewPager Tab;
TabPagerAdapter TabAdapter;
ActionBar actionBar;
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
TabAdapter = new TabPagerAdapter(getSupportFragmentManager());
Tab = (ViewPager)findViewById(R.id.pager);
Tab.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener()
{
public void onPageSelected(int position)
{
actionBar = getActionBar();
actionBar.setSelectedNavigationItem(position);
}
});
Tab.setAdapter(TabAdapter);
actionBar = getActionBar();
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
ActionBar.TabListener tabListener = new ActionBar.TabListener()
{
public void onTabReselected(android.app.ActionBar.Tab tab,FragmentTransaction ft)
{
}
public void onTabSelected(ActionBar.Tab tab, FragmentTransaction ft)
{
Tab.setCurrentItem(tab.getPosition());
}
public void onTabUnselected(android.app.ActionBar.Tab tab,FragmentTransaction ft)
{
}};
actionBar.addTab(actionBar.newTab().setText("Connessione").setTabListener(tabListener));
actionBar.addTab(actionBar.newTab().setText("Mappa").setTabListener(tabListener));
}
public void send(String one, String two)
{
Mapped map = new Mapped();
final Bundle bundle = new Bundle();
bundle.putString("Position",one);
bundle.putString("ID",two);
map.setArguments(bundle);
getSupportFragmentManager().beginTransaction().replace(R.id.mapView, map).commit();
}
}
The communication between fragments must be done through the parent FragmentActivity like documentation says:
Often you will want one Fragment to communicate with another, for example to change the content based on a user event. All Fragment-to-Fragment communication is done through the associated Activity. Two Fragments should never communicate directly.
The problem is how to refresh something in the ui. If you call replace to make the back navigation, in the OnCreateView of the new fragment you get the value of the parent activity. If you use the popbackstack to navigate backwards you should implement an interface.if you show the two fragments together, only use the fragment activity to refresh data.You can chage this:
getSupportFragmentManager().beginTransaction().replace(R.id.mapView, map).commit();
for this:
MyFragment myFragment = (MyFragment) getFragmentManager().findFragmentById(R.id.test_fragment);
if(myFragment!=null){
myFragment.update();
}
I'll give you some links to talk about this:
http://developer.android.com/training/basics/fragments/communicating.html
https://stackoverflow.com/a/9977370/944630
How to pass data between fragments
hope you help
You could try this solution:
add Mapped with a tag myMap:
Mapped map = new Mapped();
getSupportFragmentManager().beginTransaction().add(R.id.mapView, map, "myMap").commit();
make a method in Mapped, named addData(Bundle data), then you can pass data by this method when you need.
after data added to Mapped, then refresh it by:
Fragment mapFrg = getSupportFragmentManager().findFragmentByTag("myMap");
getSupportFragmentManager().beginTransaction().detach(mapFrg);
getSupportFragmentManager().beginTransaction().atach(mapFrg).commit();
in Mappde, in onCreateView(), each time check MapView is null or not
Hope this help.

ActionBar navigation tab item that starts an activity?

I have an activity that uses ActionBarSherlock to show an action bar with navigation tabs. I need one of those tabs to open another activity (taking over the whole screen) when it is tapped. I built a custom TabListener to achieve this, but it fires when the tab contents are initially rendered, not just when it's manually selected.
I can't see a way to catch a traditional onClick event, so I assume I need to handle this in the TabListener and somehow distinguish the initial selection from a later manual selection, but how? I could use a counter each time the tab is selected and only start the secondary activity if the counter is above zero, but that looks like an ugly hack. I was hoping there was a way to handle a "click" as opposed to a "selection" as the latter includes both the initial display of the views, as well as later manual clicks.
I attach the listener to the action bar navigation tab like this:
tab.setTabListener(new TabDiseaseSelectorListener(this));
And then the listener looks like this:
public class TabDiseaseSelectorListener implements ActionBar.TabListener {
private final Activity mActivity;
public TabDiseaseSelectorListener(Activity activity) {
mActivity = activity;
}
public void onTabSelected(ActionBar.Tab tab, FragmentTransaction unused) {
Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
intent.setClass(mActivity, DiseaseSelector.class);
startActivity(intent);
}
public void onTabUnselected(ActionBar.Tab tab, FragmentTransaction unused) {
}
public void onTabReselected(ActionBar.Tab tab, FragmentTransaction ft) {
}
}
I tried using onTabReselected() but that only fires if the tab is already selected and the user taps it again.

Transaction between fragments only inside one ActionBar Tab

I have an app with three tabs (ActionBar Tabs), each one with one fragment at a time.
TabListener
TabsActivity
Tab1 -> ListFragment1 -> ListFragment2 -> Fragment3
Tab2 -> Tab2Fragment
Tab3 -> Tab3Fragment
The problem is when I create the FragmentTransaction (inside OnListItemClicked) from ListFragment1 to ListFragment2, the fragments inside the other tabs also change to ListFragment2.
In the end, I want to change fragments only inside on tab and preserve the state of the other tabs.
I'm already saving the state (OnSavedInstance()).
Do you know what I'm missing here?
Some of the code:
public class TabsActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.tabs);
// setup Action Bar for tabs
ActionBar actionBar = getActionBar();
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
// instantiate fragment for the tab
Fragment networksFragment = new NetworksFragment();
// add a new tab and set its title text and tab listener
actionBar.addTab(actionBar.newTab().setText("Tab1")
.setTabListener(new TabsListener(ListFragment1)));
// instantiate fragment for the tab
Fragment historyFragment = new HistoryFragment();
// add a new tab and set its title text and tab listener
actionBar.addTab(actionBar.newTab().setText("Tab2")
.setTabListener(new TabsListener(Tab2Fragment)));
// instantiate fragment for the tab
Fragment settingsFragment = new SettingsFragment();
// add a new tab and set its title text and tab listener
actionBar.addTab(actionBar.newTab().setText("Tab3")
.setTabListener(new TabsListener(Tab3Fragment)));
}
}
public class TabsListener implements ActionBar.TabListener {
private Fragment frag;
// Called to create an instance of the listener when adding a new tab
public TabsListener(Fragment networksFragment) {
frag = networksFragment;
}
#Override
public void onTabReselected(Tab arg0, FragmentTransaction arg1) {
// TODO Auto-generated method stub
}
#Override
public void onTabSelected(Tab tab, FragmentTransaction ft) {
ft.add(R.id.fragment_container, frag, null);
}
#Override
public void onTabUnselected(Tab tab, FragmentTransaction ft) {
ft.remove(frag);
}
}
public class ListFragment1 extends ListFragment {
#Override
public void onListItemClick(ListView l, View v, int position, long id) {
getListView().setItemChecked(position, true);
ListFragment2 fragment2 = ListFragment2.newInstance(position);
FragmentTransaction ft = getFragmentManager().beginTransaction();
ft.replace(R.id.fragment_container, fragment2);
ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
ft.addToBackStack(null);
ft.commit();
}
}
You're not missing anything (or I'm missing it too).
I searched long and hard for a way to do this "properly" but I couldn't find anything. What I ended up doing is writing my own backstack logic.
Unfortunately my employer owns my code so I can't share any of that verbatim, but here was my approach:
Create an enum with one entry for each of your tabs. Let's call it TabType.
Now create an instance variable tabStacks of type HashMap<TabType, Stack<String>>. Now you can instantiate one stack for each tab - each stack is a list of tags, as specified by Fragment.getTag(). This way you don't have to worry about storing references to Fragments and whether they're going to disappear on you when you rotate the device. Any time you need a reference to a Fragment, grab the right tag off the stack and use FragmentManager.findFragmentByTag().
Now whenever you want to push a Fragment onto a tab, generate a new tag (I used UUID.randomUUID().toString()) and use it in your call to FragmentTransaction.add(). Then push the tag on top of the stack for the currently displayed tab.
Be careful: when you want to push a new fragment on top of an old one, don't remove() the old one, since the FragmentManager will consider it gone and it will be cleaned up. Be sure to detach() it, and then attach() it later. Only use remove() when you're permanently popping a Fragment, and only use add() the first time you want to show it.
Then, you'll have to add some relatively simple logic to your TabListener. When a tab is unselected, simply peek() at its stack and detatch() the associated Fragment. When a tab is selected, peek() at the top of that stack and attach() that fragment.
Lastly, you'll have to deal with Activity lifecycle quirks (like orientation changes). Persist your Map of Stacks as well as the currently selected tab, and unpack it again in your onCreate(). (You don't get this packing and unpacking for free, but it's pretty easy to do.) Luckily your TabType enum is Serializable so it should be trivial to put into a Bundle.

onCreateOptionsMenu is being called too many times in ActionBar using tabs

Here is my problem. I have an app where I am using ActionBar Sherlock with tabs, fragments with option menus. Every time I rotate the emulator, menus are added for all the fragments even those that are hidded/removed (I tried both).
This is the setting: One FragmentActivity, that has an ActionBar with
final ActionBar bar = getSupportActionBar();
bar.addTab(bar.newTab()
.setText("1")
.setTabListener(new MyTabListener(new FragmentList1())));
bar.addTab(bar.newTab()
.setText("2")
.setTabListener(new MyTabListener(new FragmentList2())));
bar.addTab(bar.newTab()
.setText("3")
.setTabListener(new MyTabListener(new FragmentList3())));
bar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
bar.setDisplayShowHomeEnabled(true);
bar.setDisplayShowTitleEnabled(true);
The tabs all use the same Listener:
private class MyTabListener implements ActionBar.TabListener {
private final FragmentListBase m_fragment;
public MyTabListener(FragmentListBase fragment) {
m_fragment = fragment;
}
public void onTabSelected(ActionBar.Tab tab, FragmentTransaction ft) {
FragmentManager fragmentMgr = ActivityList.this.getSupportFragmentManager();
FragmentTransaction transaction = fragmentMgr.beginTransaction();
transaction.add(R.id.frmlyt_list, m_fragment, m_fragment.LIST_TAG);
transaction.commit();
}
public void onTabUnselected(ActionBar.Tab tab, FragmentTransaction ft) {
FragmentManager fragmentMgr = ActivityList.this.getSupportFragmentManager();
FragmentTransaction transaction = fragmentMgr.beginTransaction();
transaction.remove(m_fragment);
transaction.commit();
}
public void onTabReselected(ActionBar.Tab tab, FragmentTransaction ft) {
}
}
Each subclass of FragmentListBase has its own menu and therefore all 3 subclasses have :
setHasOptionsMenu(true);
and the appropriate
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
Log.d(TAG, "OnCreateOptionsMenu");
inflater.inflate(R.menu.il_options_menu, menu);
}
When I run the app I can see that the onCreateOptionsMenu is being called multiple times, for all the different fragments.
I'm totally stumped.
I tried posting the most code as possible without being overwhelming, if you find that something is missing, please advise.
[Edit]
I added more logging, and it turns out that the fragment is being attached twice (or more) on rotation. One thing that I notice is that everything is being called multiple times except for the onCreate() method which is being called only once.
06.704:/WindowManager(72): Setting rotation to 0, animFlags=0
06.926:/ActivityManager(72): Config changed: { scale=1.0 imsi=310/260 loc=en_US touch=3 keys=1/1/2 nav=1/2 orien=L layout=0x10000014 uiMode=0x11 seq=35}
07.374:/FragmentList1(6880): onAttach
07.524:/FragmentList1(6880): onCreateView
07.564:/FragmentList1(6880): onAttach
07.564:/FragmentListBase(6880): onCreate
07.564:/FragmentList1(6880): OnCreateOptionsMenu
07.574:/FragmentList1(6880): OnCreateOptionsMenu
07.604:/FragmentList1(6880): onCreateView
[Edit 2]
Ok, I started tracing back into Android code and found this part here (that I edited to shorten this post).
/com_actionbarsherlock/src/android/support/v4/app/FragmentManager.java
public boolean dispatchCreateOptionsMenu(Menu menu, MenuInflater inflater) {
if (mActive != null) {
for (int i=0; i<mAdded.size(); i++) {
Fragment f = mAdded.get(i);
if (f != null && !f.mHidden && f.mHasMenu) {
f.onCreateOptionsMenu(menu, inflater);
}
}
}
The problem is that mAdded does indeed have multiple instances of FragmentList1 in it, so the onCreateOptionsMenu() method is "correctly" being called 3 times, but for different instances of the the FragmentList1 class. What I don't understand is why that class is being added multiple times... But that is a hell of a good lead.
I seem to have found the problem(s). I say problem(s) because on top of the multitude of menus, there is now also an Exception.
1) the call to
bar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
which is after the calls to addTab() has a side effect of calling onTabSelected(). My TabListener would then add a FragmentList1 to the FragmentManager
2) rotating the device would destroy the Activity as expected, but would not destroy the Fragments. When the new Activity is created after rotation it would do two things :
create another set of Fragments that it would add to the FragmentManager. This is what was causing the multitude of Menus
call onTabSelected (via setNavigationMode()) which would perform the following code:
if (null != fragmentMgr.findFragmentByTag(m_fragment.LIST_TAG)) {
transaction.attach(m_fragment);
transaction.show(m_fragment);
}
else {
transaction.add(R.id.frmlyt_list, m_fragment, m_fragment.LIST_TAG);
}
Basically if the fragment is already in the FragmentManager there is no need to add it, just show it. But there lies the problem. It's not the same Fragment! It's the Fragment that was created by the earlier instance of the Activity. So it would try to attach and show this newly created Fragment which would cause an Exception
The Solution.
There were a few things to do in order to fix all of this.
1) I moved the setNavigationMode() above the addTab()s.
2) this is how I now create my tabs:
FragmentListBase fragment = (FragmentListBase)fragmentMgr.findFragmentByTag(FragmentList1.LIST_TAG_STATIC);
if (null == fragment) {
fragment = new FragmentList1();
}
bar.addTab(bar.newTab()
.setText("1")
.setTabListener(new MyTabListener(fragment)));
So upon Activity creation I have to check to see if the Fragments are already in the FragmentManager. If they are I use those instances, if not then I create new ones. This is done for all three tabs.
You may have noticed that there are two similar labels: m_fragment.LIST_TAG and FragmentList1.LIST_TAG_STATIC. Ah, this is lovely... ( <- sarcasm)
In ordrer to use my TagListener polymorphically I have declared the following non static variable in the base class:
public class FragmentListBase extends Fragment {
public String LIST_TAG = null;
}
It is assigned from inside the descendents and allows me to look in the FragmentManager for the different descendents of FragmentListBase .
But I also need to search for specific descendents BEFORE they are created (because I need to know if I must create them or not), so I also have to declare the following static variable.
public class FragmentList1 extends FragmentListBase {
public final static String LIST_TAG_STATIC = "TAG_LIST_1";
public FragmentList1() {
LIST_TAG = LIST_TAG_STATIC;
};
}
Suffice to say that I am disapointed that nobody came up with this simple and elegant solution ( <- more sarcasm)
Thanks a lot to Jake Wharton who took the time to look at this for me :)
public FragmentListBase() {
setRetainInstance(true);
setHasOptionsMenu(true);
}
This will save/restore the individual states of each of the fragments upon rotation.
Another simple change you might want to make is calling transaction.replace(R.id.frmlyt_list, m_fragment, m_fragment.LIST_TAG) in the tab selected callback and getting rid of the content in the unselected callback.
I had this very similar issues with "stackable" menus on rotation. I don't use tabs but I do use ViewPager with FragmentStatePagerAdapter so I can't really reuse my Fragments. After banging my head for 2 days I found very simple solution. Indeed the problem seems to be with onCreateOptionsMenu called multiple times. This little code snippet takes care (masks?) of all the problems:
/** to prevent multiple calls to inflate menu */
private boolean menuIsInflated;
#Override
public void onCreateOptionsMenu(final Menu menu, final MenuInflater inflater) {
if (!menuIsInflated) {
inflater.inflate(R.menu.job_details_fragment_menu, menu);
menuIsInflated = true;
}
}
What worked for me was moving the setHasMenuOptions(true) to the calling activity ie the activity in which the fragment was declared. I previously had it in the onCreate method of the fragment.
Here is the code snippet:
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
FragmentManager fragmentManager = getFragmentManager();
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
ForecastFragment forecastFragment = new ForecastFragment();
forecastFragment.setHasOptionsMenu(true);
fragmentTransaction.add(R.id.fragment, forecastFragment);
fragmentTransaction.commit();
}
Just a quite note on your polymorphic tag frustrations.
Declare your base class like so:
public abstract class ListFragmentBase {
protected abstract String getListTag();
}
Now declare your sub classes something like this:
public class FragmentList1 extends ListFragmentBase {
public static final String LIST_TAG = "TAG_LIST_1";
#Override
protected String getListTag() {
return LIST_TAG;
}
}
Now the polymorphic way to get the instance tag is like this:
ListFragmentBase frag = new FragmentList1();
frag.getListTag();
Get the tag statically like so:
FragmentList1.LIST_TAG;

Categories

Resources