Android Development-crimina

Source: Internet
Author: User

This time we're doing an application that records the bad habits of life.

This is what he looks like when he finishes.

First we create a fragment transaction

if (fragment == null) {?        fragment = new CrimeFragment();? fm.beginTransaction()? .add(R.id.fragment_container, fragment)? .commit();

This is its layout file.

<?xml version= "1.0" encoding= "Utf-8"?>

<framelayout

xmlns:android="Http://schemas.android.com/apk/res/android"

android:id="@+id/fragment_container"

android:layout_width= "match_parent" android:layout_height="match_parent"/>

Creating the Crime class
public class Crime {    private UUID mId;    Private String Mtitle;    Private Date mdate;    Private Boolean msolved;    Public Crime () {        mId = Uuid.randomuuid ();        Mdate = new Date ();    }    Public UUID Getmid () {        return mId;    }    Public String Getmtitle () {        return mtitle;    }    public void Setmtitle (String mtitle) {        this.mtitle = mtitle;    }    Public Date getmdate () {        return mdate;    }    public void Setmdate (Date mdate) {        this.mdate = mdate;    }    public Boolean ismsolved () {        return msolved;    }    public void Setmsolved (Boolean msolved) {        this.msolved = msolved;    }}
Using Viewpager
    • Finally we add vi to the UI for pager, allowing the user to swipe the screen left and right to switch to the detail page of different list items.

    • Create Crimepageractivity

···
protected void OnCreate (Bundle savedinstancestate) {
Super.oncreate (savedinstancestate);
Setcontentview (R.layout.activity_crime_pager);}
···

-Set Pager Adapter

···
Mviewpager = (Viewpager) Findviewbyid (R.id.crime_view_pager);

  Mcrimes = Crimelab.    Get (this). Getcrimes ();    Fragmentmanager Fragmentmanager = Getsupportfragmentmanager (); Mviewpager.setadapter (new fragmentstatepageradapter (fragmentmanager) {@override public Fragment getitem (int position" {Crime Crime = Mcrimes. Get (position); return crimefragment.newinstance (Crime.getid ());} @override public int getcount (return mcrimes.size ();});   

Android Development-crimina

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.