English 中文(简体)
在制定申请时,究竟应当把事件处理器储存在什么地方?
原标题:Where should event handlers be ideally stored when developing the application?
  • 时间:2012-01-12 07:54:40
  •  标签:
  • android

我是“网络”流动开发商,自一开始与甲状腺合作以来,我注意到,储存我活动处理者意见的唯一途径是通过活动档案,或设立一个小组,召集所有这些活动的听众。 难道有人能提出最佳办法,即能够做些什么,使所有活动处理者都得到最少的cl子和储存?

最佳回答

“cl”的主观性取决于你在执行你的活动处理器方面的效率如何,以及你的看法如何复杂。

例如,我在这里看到了类似SO...的范例守则。

button1.setOnClickListener(new View.OnClickListener {...});
button2.setOnClickListener(new View.OnClickListener {...});
button3.setOnClickListener(new View.OnClickListener {...});

每种情况下,每个个人匿名听众<代码>Button往往履行非常相似的职能(启动活动1,开始活动2.......)。 最为清洁的方式是执行<代码>。 View.OnClickListener on Actative

button1.setOnClickListener(this);

......(按每条<代码>Button)获得<代码>的资源。 意见在听众中获得通过,以确定被点击和需要做什么。 令我惊讶的是,有多少人没有这样做。

As for creating a separate class (or classes) to hold listeners, that gets tricky depending on how many activities you have going on. Maintaining the listeners separately has two downsides.

首先,如果你不采用“<>代谢”模式,即使用匿名听众或直接执行听众,那就意味着你利用你的助老会的听众开展各种活动(有时会延长)。 每次延长您的<条码>活动<> 代码>时,你都需要确保单独类别得到更新,以应付这一变化——有可能是视而不见的,因为你想要从<条码>活动<<>代码/代码”中找到新内容,而你的普通听众却不处理这种问题。

The second potential problem is in the way Android works (depending on your app). An Android Activity is meant to be modular - if it displays photos or images or documents of a particular format then it should be as self-contained as possible. Having a separate class with a multitude of listeners in means that a very simple Activity meant to do a very simple task ends up loading a bloat of a class (or classes) which contains a whole load of listeners which aren t relevant.

简明扼要——选择每个<代码>的听众,并保持其自成一体。 如果你感到存在任何重复,确定自己的基础课程并从那里延伸。

问题回答

不清楚你想要取得什么结果。 据我所知,你不想设立任何活动分组,以处理国际律师联合会的活动。 如果是的话,那是真的令人厌恶的——你如何在活动中表明这些观点?





相关问题
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 ...

热门标签