相关疑难解决方法(0)

在Android中使用Fragments而不是Views有什么好处?

开发时Android,您可以将目标(或最小)sdk设置为4(API 1.6)并添加android兼容包(v4)以添加支持Fragments.昨天我做了这个并成功实现Fragments了可视化来自自定义类的数据.

我的问题是:使用的好处是什么Fragments,而不是简单地从自定义对象获取View,并且仍然支持API 1.5?

例如,假设我有类Foo.java:

public class Foo extends Fragment {

    /** Title of the Foo object*/
    private String title;
    /** A description of Foo */
    private String message;

    /** Create a new Foo
     * @param title
     * @param message */
    public Foo(String title, String message) {
        this.title = title;
        this.message = message;
    }//Foo

    /** Retrieves the View to display (supports API 1.5. To use,
     * remove 'extends Fragment' from the class …
Run Code Online (Sandbox Code Playgroud)

android software-design android-lifecycle android-fragments android-view

102
推荐指数
2
解决办法
4万
查看次数

Android片段与复合控件

为什么要使用Android 3.0片段而不是复合控件?可以创建一个View继承者或复合控件一次并在任何地方使用它.

我已经阅读了http://android-developers.blogspot.com/2011/02/android-30-fragments-api.html但未找到答案.

controls android fragment android-lifecycle android-fragments

19
推荐指数
2
解决办法
7778
查看次数

自定义视图调用startActivityForResult

我创建了自定义复合视图,其中包含拍摄照片的功能.

我这样称呼它(从视图):

Intent intent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
((Activity)mContext).startActivityForResult(intent, index);
Run Code Online (Sandbox Code Playgroud)

这部分很好用.我不知道怎么做是如何onActivityResult在我的自定义视图中实现的?

或者我应该在Activity中捕获这个并重新路由到我的视图中?看起来不是很好的解决方案..

android android-layout

13
推荐指数
3
解决办法
1万
查看次数