English 中文(简体)
活动扩展类别
原标题:Extending class for activity

I m完全是新到的Anthony(Java)发展,I m如此夸大了! 谷歌的制定者指南是弹性的,我在一个小的时间内学到了很多东西。 它甚至在晚上让我觉醒;

今天 我接着说,我可以理解一些东西。 它涉及扩大课程。 该指南说:

Tip: If your application contains multiple activities and some of them provide the same Options Menu, consider creating an activity that implements nothing except the onCreateOptionsMenu() and onOptionsItemSelected() methods. Then extend this class for each activity that should share the same Options Menu. This way, you have to manage only one set of code for handling menu actions and each descendant class inherits the menu behaviors.

我看不出的是,如何扩大一等。 我要说的是MainActativeSubActative。 在这两项活动中,我想有相同的菜单,这样我就有了<>MainMenuActative。 我如何将这一类别扩大到这两种活动?

是的,我确实在网上搜查了,但却找不到任何东西。 我真的想理解这一点,因此我希望任何人都能够帮助我解答某些条码加解释。 advance!

最佳回答

它们的含义如下:

通常,你会:

public class MyActivity extends Activity{...}

如果这些活动中有4-5-6,其中每一个活动都使用相同的菜单,那么你就能够照抄和复制第4-5-6号法律。 或者你可以这样做:

public class BaseActivity extends Activity{
    
    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        //My menu code  
    }
}

并且将这一类别用于你的4-5-6...... 活动:

public class MyActivity extends BaseActivity{...}

这样,你就不需要把你的菜单复制到你所有的造物。 此外,你的活动不一定是4-5-6. 班级将小块菜单的制造线ed。 菜单现在也载于<编码>。 MyActative。


http://xahlee.info/java-a-day/extend.html” rel=“nofollow noreferer”>here,其中解释了extends的含义。

问题回答

这确实非常简单。

http://www.ohchr.org。

public class MainMenuActivity extends Activity {
   //Override or add whatever functionality you want other classes to inherit.
}

http://www.ohchr.org。

public class MainActivity extends MainMenuActivity {
   //Add what is specific to MainActivity. The menu will be inherited from MainMenuActivity.
}

http://www.ohchr.org。

public class SubActivity extends MainMenuActivity {
   //Add what is specific to SubActivity. The menu will be inherited from MainMenuActivity.
}




相关问题
Android - ListView fling gesture triggers context menu

I m relatively new to Android development. I m developing an app with a ListView. I ve followed the info in #1338475 and have my app recognizing the fling gesture, but after the gesture is complete, ...

AsyncTask and error handling on Android

I m converting my code from using Handler to AsyncTask. The latter is great at what it does - asynchronous updates and handling of results in the main UI thread. What s unclear to me is how to handle ...

Android intent filter for a particular file extension?

I want to be able to download a file with a particular extension from the net, and have it passed to my application to deal with it, but I haven t been able to figure out the intent filter. The ...

Android & Web: What is the equivalent style for the web?

I am quite impressed by the workflow I follow when developing Android applications: Define a layout in an xml file and then write all the code in a code-behind style. Is there an equivalent style for ...

TiledLayer equivalent in Android [duplicate]

To draw landscapes, backgrounds with patterns etc, we used TiledLayer in J2ME. Is there an android counterpart for that. Does android provide an option to set such tiled patterns in the layout XML?

Using Repo with Msysgit

When following the Android Open Source Project instructions on installing repo for use with Git, after running the repo init command, I run into this error: /c/Users/Andrew Rabon/bin/repo: line ...

Android "single top" launch mode and onNewIntent method

I read in the Android documentation that by setting my Activity s launchMode property to singleTop OR by adding the FLAG_ACTIVITY_SINGLE_TOP flag to my Intent, that calling startActivity(intent) would ...

From Web Development to Android Development

I have pretty good skills in PHP , Mysql and Javascript for a junior developer. If I wanted to try my hand as Android Development do you think I might find it tough ? Also what new languages would I ...

热门标签