Android的碎片混乱 [英] Android Fragment Confusion

查看:144
本文介绍了Android的碎片混乱的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个关于Android中正确的逻辑使用碎片问题。我知道,它被设计用来改善片剂的经验,但这意味着片段通常只应用于这一目的?还是会成为发展的实践穷使用片段作为一个自定义的复合视图替换?

I have a question about the correct logical use of fragments in Android. I know that it was designed to be used to improve tablet experience, but does this imply that fragments should generally ONLY be used for this purpose? Or would it be poor development practice to use fragments as a replacement for a custom compound View?

例如,我写一个应用程序保持理货。当比分板产生,它会创建一个ScoreCell,自定义复合控制,在滚动型每个玩家。我想这样做(但不知道怎样作为一个视图)是处理由含有活性激活内部OnClickListeners:每个ScoreCell有球员的名字,我想长期preSS到一个TextView startActivityForResult()弹出打开一个输入对话框更改ScoreCell的名称。但看到的的onActivityResult()方法是在视图中不可用,这将是正确的我,而不是使每ScoreCell片段?

For example, I am writing an app to keep tally. When the score sheet is produced, it creates a "ScoreCell," a custom compound control, for each player in a ScrollView. What I want to do(but don't see how as a View) is handle internal OnClickListeners that are activated by the containing activity: each ScoreCell has a TextView for the players' name, which I want to long-press to startActivityForResult() to pop open an input dialog to change the name of the ScoreCell. But seeing as the method for OnActivityResult() is unavailable in a View, would it be correct for me to instead make each ScoreCell a fragment?

下面是活动的照片来帮助理解我需要什么/我困惑的逻辑

推荐答案

有在这里很多问题,让我通过他们去。

There are many questions in here, let me go through them.


  1. 没有碎片并不意味着只是为平板电脑的经验,一般来说,他们允许你创建更加模块化和适应性布局(思班)。他们在平板电脑布局/景观非常有益的,但​​也给你重用组件。

  1. No fragments are not meant just for tablet experience, in general they allow you to create more modular and adaptable layouts (think classes). They are extremely helpful in tablet layouts/landscape, but also give you reusable components.

与此同时,一个片段是不是在这里正确的选择......这是很容易使用列表视图,再加上自定义单元格的布局。而不是使用其他活动,以显示一个对话框,简单地调用新的对话框()和dialog.show()。的活性应仅用来作为对话是否将用于由用户通过的很长一段时间,并提供了一​​个新的活动(动作)

At the same time, a fragment is not the right choice here... It is much easier to use a listview, coupled with a custom cell layout. Instead of using another activity to display a dialog simply call new Dialog() and dialog.show(). An activity should only be used as a dialog if it will be used by the user by a long period of time and provides a new "activity" (action)

这篇关于Android的碎片混乱的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆