Development of Android Criminalintent project (one)

Source: Internet
Author: User

Objective

The development project is an application called Criminalintent, which can record a variety of office habits in detail. The app's record of bad habits includes titles, dates and images, support for finding parties in contacts, and protests via e-mail, Twitter, Facebook, or some other social app.

Introduction of Fragment

Using fragment instead of activity to manage the app UI, you can circumvent the restrictions on the activity usage rules of the Android system.

Fragment is a controller object that the activity can delegate to perform tasks. These tasks are typically administrative user interfaces. The managed user interface can be a full screen or part of a full screen.

Depending on the needs of the application and the user, the user interface can be assembled or reorganized using fragment and activity together. The activity view is the same view throughout the life cycle, so you don't have to worry about violating the activity usage rules of the Android system.

How do I support displaying lists and details on the same screen? In fact, the activity view of such an application consists of a list of fragment and a detail fragment. The detail view is responsible for displaying the details of the list item. Select a different list item to display the corresponding detail view. The activity is responsible for replacing another detail fragment with one detail fragment. In this way, the activity is not destroyed during the view switching process.

Development Criminalintent

The development of the Criminalintent project is more complicated, so it has to be step-by-step.

Add Dependencies in Android Studio

The support library version that you want to use fragment comes from the AppCompat library. To use the AppCompat support library, the project must include it in a dependency relationship. Modify the Build.gradle file.

Apply plugin: ' Com.android.application 'Android {compilesdkversion25buildtoolsversion"25.0.2"Defaultconfig {ApplicationID"Classroom.criminalintent"minsdkversion9targetsdkversion25Versioncode1Versionname"1.0"Testinstrumentationrunner"Android.support.test.runner.AndroidJUnitRunner"} buildtypes {release {minifyenabledfalseproguardfiles Getdefaultproguardfile (' Proguard-android.txt '), ' Proguard-rules.pro '}}}dependencies {compile Filetree (dir:' Libs ', include: [' *.jar ']) Androidtestcompile (' com.android.support.test.espresso:espresso-core:2.2.2 ', {Exclude group:' Com.android.support ', module: ' Support-annotations '}) Compile' com.android.support:appcompat-v7:25.2.0 'Testcompile' junit:junit:4.12 'Compile' com.android.support:recyclerview-v7:25.2.0 'Compile' com.android.support:recyclerview-v7:25.2.0 'Compile' com.android.support.constraint:constraint-layout:1.0.2 '}
Creating the Crime class
 Public classCrime {PrivateUUID mId; PrivateString Mtitle; PrivateDate mdate; Private Booleanmsolved;  PublicCrime () {mId=Uuid.randomuuid (); Mdate=NewDate (); }     PublicUUID Getmid () {returnmId; }     PublicString Getmtitle () {returnMtitle; }     Public voidSetmtitle (String mtitle) { This. Mtitle =Mtitle; }     PublicDate getmdate () {returnmdate; }     Public voidsetmdate (Date mdate) { This. mdate =mdate; }     Public Booleanismsolved () {returnmsolved; }     Public voidSetmsolved (Booleanmsolved) {         This. msolved =msolved; }}
Creating the Crimefragment Class

Create a new Java class and modify the code.

 Public class extends Fragment {}

Note that when inheriting the fragment class, you need to inherit Android.support.v4.app. This is the fragment that supports the library version.

import android.support.v4.app.Fragment;
Upgrade the model layer for criminalintent applications

Create the Crimelab.java and modify the code.

     Public Crime getcrime (UUID id) {        for  (Crime crime:mcrimes) {            if  ( Crime.getmid (). Equals (ID)) {                return  crime;            }        }         return NULL ;    }

Creates a list that can hold crime objects.

PrivateList<crime>Mcrimes;PrivateCrimelab (Context context) {Mcrimes=NewArraylist<>();  for(inti = 0; I < 100; i++) {Crime Crime=NewCrime (); Crime.setmtitle ("Crime #" +i); Crime.setmsolved (i% 2 = = 0);//every other onemcrimes.add (crime); }    }     PublicList<crime>Getcrimes () {returnMcrimes; }     PublicCrime getcrime (UUID id) { for(Crime crime:mcrimes) {if(Crime.getmid (). Equals (ID)) {returncrime; }        }        return NULL; }

Where this part of the code is used to generate 100 crime.

 for (int i = 0; i < i++) {            new  Crime ();            Crime.setmtitle ("Crime #" + i);             % 2 = = 0); // every other one             mcrimes.add (crime);        }
Creating a user interface using layouts and components

In the above diagram, the interface can be view management, compared to a little bit of code in the background, a lot of convenience.

Development of Android Criminalintent project (one)

Related Article

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.