Tutorial Programming

Tutorial Preload Android Loading 


Hallo sahabat saya akan menjelaskan tentang bagaimana mengunakan preload loading sesuai kebutuhan pada aplikasi kalian, preload ini sering digunakan saat menunggu loading sebuah data yang akan ditampilkan nah langsung aja kita sahabat.

1. Buatlah project android kalian

2. Lalu copy coding MainActivity.java tersebut

package com.example.tutorintent;

import android.os.Bundle;
import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Intent;
import android.view.Menu;
import android.view.View;


public class MainActivity extends Activity { 
   
	@Override  
	protected void onCreate(Bundle savedInstanceState) {       
	super.onCreate(savedInstanceState);       
	setContentView(R.layout.activity_main);   
	}

	public void NahIniAbout(View view) {
		
	//Ini Loadingnya			
	final ProgressDialog myProgressDialog = ProgressDialog.show(MainActivity.this, "Loading", "Please Wait...", true);   				
	new Thread() {					
		public void run() {					
		try{Thread.sleep(1000);}					
		catch (Exception e) {}					
		myProgressDialog.dismiss();					
		MainActivity.this.finish();
		}    
	}     
	.start();
			
			
	Intent objIntent = new Intent(getApplicationContext(), About.class);     
	startActivity(objIntent); 
	}
    
    
	public void BalekOy(View view) {  
	
	Intent objIntent = new Intent(getApplicationContext(), MainActivity.class);       
	startActivity(objIntent);   
	
	}

}


3. Lalu buat class lagi di dalam project kalian, yang setarap MainActivity.java , misalnya kalau saya membuat About.java

4. selanjutnya copy coding About.java tersebut

package com.example.tutorintent;

import android.os.Bundle;
import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Intent;
import android.view.Menu;
import android.view.View;

public class About extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.about);
    }


    public void NahIniAbout(View view) {
    	
    	//Ini Loadingnya
    	final ProgressDialog myProgressDialog = ProgressDialog.show(About.this, "Loading", "Please Wait...", true);   	
        new Thread() {
    	    	public void run() {
    	    	try{Thread.sleep(1000);}
    	    	catch (Exception e) {}
    	    	myProgressDialog.dismiss();
    	    	About.this.finish();
    	    	} 
        }
        .start();
        
        Intent objIntent = new Intent(getApplicationContext(), About.class);
        startActivity(objIntent);
    }
    
    public void BalekOy(View view) {
        Intent objIntent = new Intent(getApplicationContext(), MainActivity.class);
        startActivity(objIntent);
    }
    
}



5. copy coding activity_main.xml tersebut

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".MainActivity" >

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/hello_world" />

    <Button
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/textView1"
        android:onClick="BalekOy"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="67dp"
        android:text="Home" />

    <Button
        android:id="@+id/button2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/button1"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="37dp"
        android:onClick="NahIniAbout"
        android:text="About" />

</RelativeLayout>

6. Buat layout baru dengan nama about.xml di res/layout/about.xml misalkan.

7. lalu copy coding tersebut di about.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".MainActivity" >

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="About Ary EJFA" />

    <Button
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/textView1"
        android:onClick="BalekOy"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="67dp"
        android:text="Home" />

    <Button
        android:id="@+id/button2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/button1"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="37dp"
        android:onClick="NahIniAbout"
        android:text="About" />

</RelativeLayout>

8. Setelah itu copy coding AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.tutorintent"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="10"
        android:targetSdkVersion="10" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="com.example.tutorintent.MainActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity
            android:name=".About">
        </activity>
    </application>

</manifest>

9. Lalu run aplikasi kalian.

10. Oke seleseai project kalian sahabat.





Sekian tutorial saya semoga bermanfaat

No comments:

Post a Comment

Tutorial Programming Designed by Templateism | Ary EJFA Copyright © 2015

Theme images by richcano. Powered by Blogger.