欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  移动技术

Android学习 -- photoGallery应用的创建方法

程序员文章站 2022-12-11 09:09:42
今天的任务为创建photogallery应用,代码如下: photogalleryactivity.java: package com.example.a49840.photogallery;...

今天的任务为创建photogallery应用,代码如下:

photogalleryactivity.java:

package com.example.a49840.photogallery;

import android.support.v4.app.fragment;

public class photogalleryactivity extends singlefragmentactivity {

    @override
    protected fragment createfragment() {
        return photogalleryfragment.newinstance();
    }
}

fragment_photo_gallery.xml:



phtotgalleryfragment.java:

package com.example.a49840.photogallery;

import android.os.asynctask;
import android.os.bundle;
import android.support.v4.app.fragment;
import android.support.v7.widget.gridlayoutmanager;
import android.support.v7.widget.recyclerview;
import android.view.layoutinflater;
import android.view.view;
import android.view.viewgroup;
import android.widget.textview;

import java.util.arraylist;
import java.util.list;


public class photogalleryfragment extends fragment {
    private recyclerview mphotorecyclerview;

    public static photogalleryfragment newinstance() {
        return new photogalleryfragment();
    }

    @override
    public void oncreate(bundle savedinstancestate) {
        super.oncreate(savedinstancestate);
        setretaininstance(true);
    }

    @override
    public view oncreateview(layoutinflater inflater, viewgroup container,
                             bundle savedinstancestate) {
        view v = inflater.inflate(r.layout.fragment_photo_gallery, container, false);

        mphotorecyclerview = (recyclerview) v.findviewbyid(r.id.photo_recycler_view);
        mphotorecyclerview.setlayoutmanager(new gridlayoutmanager(getactivity(), 3));

        return v;
    }
}