Showing posts with label etutorial. Show all posts
Showing posts with label etutorial. Show all posts

Send object from one Android Activity to another using Intents


How
if you're just passing objects around then Parcelable was designed for this. It requires a little more effort to use than using Java's native serialization, but it's way faster and I mean way, WAY faster. 

From the docs, a simple example for how to implement is:

// simple class that just has one member property as an example
public class MyParcelable implements Parcelable {
    private int mData;

    /* everything below here is for implementing Parcelable */

    // 99.9% of the time you can just ignore this
    public int describeContents() {
        return 0;
    }

    // write your object's data to the passed-in Parcel
    public void writeToParcel(Parcel out, int flags) {
        out.writeInt(mData);
    }

    // this is used to regenerate your object. All Parcelables must have a CREATOR that implements these two methods
    public static final Parcelable.Creator<MyParcelable> CREATOR = new Parcelable.Creator<MyParcelable>() {
        public MyParcelable createFromParcel(Parcel in) {
            return new MyParcelable(in);
        }

        public MyParcelable[] newArray(int size) {
            return new MyParcelable[size];
        }
    };

    // example constructor that takes a Parcel and gives you an object populated with it's values
    private MyParcelable(Parcel in) {
        mData = in.readInt();
    }
}
 
Once you have your objects implement Parcelable it's just a matter of putting them into your Intents with putExtra():

Intent i = new Intent();
i.putExtra("name_of_extra", myParcelableObject);
Then you can pull them back out with getParcelableExtra():
Intent i = getIntent();
MyParcelable myParcelableObject = (MyParcelable) i.getParcelableExtra("name_of_extra");
 
 hope this code will helpful to you! :)

How to Display Progress Dialog Window Using an Activity? - Android Tutorial


After Giving a nice tutorial on how to Display a Dialog Window Using an Activity, i am again come up with a great tutorial for Android.
android tutorial

Today we gonna learn on, how to Display progress dialog window using an Activity? So lets start it!

Step 1: Using the same project created for Creating a dialog window using an activity, add the following  statements in bold to the!

MainActivity.java file: package net.learn2develop.Dialog;

import android.app.Activity; import android.app.AlertDialog; import android.app.Dialog; import android.content.DialogInterface; import android.os.Bundle; import android.view.View; import android.widget.Button; import android.widget.Toast;


import android.app.ProgressDialog; import android.os.Handler;

import android.os.Message;

public class MainActivity extends Activity {

CharSequence[] items = { “Google”, “Apple”, “Microsoft” };

boolean[] itemsChecked = new boolean [items.length];

private ProgressDialog _progressDialog;

private int _progress = 0;

private Handler _progressHandler;

/** Called when the activity is first created. */

@Override

public void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.main);

Button btn = (Button) findViewById(R.id.btn_dialog);

btn.setOnClickListener(new View.OnClickListener() {

public void onClick(View v) {

showDialog(1);

_progress = 0;

_progressDialog.setProgress(0);

_progressHandler.sendEmptyMessage(0);

}

});

_progressHandler = new Handler() {

public void handleMessage(Message msg) {

super.handleMessage(msg);

if (_progress >= 100) {

_progressDialog.dismiss();

} else {

_progress++;

_progressDialog.incrementProgressBy(1);

_progressHandler.sendEmptyMessageDelayed(0, 100);

}

}

};

    }

@Override

protected Dialog onCreateDialog(int id) {

switch (id) {

case 0:

return new AlertDialog.Builder(this)

            //...

            //...

            .create();

case 1:

_progressDialog = new ProgressDialog(this);

_progressDialog.setIcon(R.drawable.icon);

_progressDialog.setTitle(“Downloading files...”);

_progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);

_progressDialog.setButton(DialogInterface.BUTTON_POSITIVE, “Hide”, new

DialogInterface.OnClickListener() {

public void onClick(DialogInterface dialog,

int whichButton)

{

Toast.makeText(getBaseContext(),

“Hide clicked!”, Toast.LENGTH_SHORT).show();

}

});

_progressDialog.setButton(DialogInterface.BUTTON_NEGATIVE, “Cancel”, new

DialogInterface.OnClickListener() {

public void onClick(DialogInterface dialog,

int whichButton)

{

Toast.makeText(getBaseContext(),

“Cancel clicked!”, Toast.LENGTH_SHORT).show();

}

});

return _progressDialog;

}

return null;

    }

}

Step 2 : Press F11 to debug the application on the Android Emulator. Click the button to display the prong-ress dialog. Observe that the progress bar will count up to 100.
How to Display Progress Dialog Window Using an Activity? - Andorid Tutorial

have a happy tuts!!

how to Display a Dialog Window Using an Activity ? - Android Tutorial


hey guys, to day i am going to give you a fresh tutorial on android. as many people wants a dialog window in their Android apps.

To Display a dialog window, you must be familiar with basic android coding functionality!

android tutorial
1 . Using Eclipse, create a new Android project and name it Dialog. 
2 . Add the following statements in bold to the main.xml file:
version=”1.0” encoding=”utf-8”?> 
”http://schemas.android.com/apk/res/android

android:orientation=”vertical”

android:layout_width=”fill_parent”

android:layout_height=”fill_parent” > < span="">

android:layout_width=”fill_parent”

android:layout_height=”wrap_content”

android:text=”@string/hello” />

span="">

android:id=”@+id/btn_dialog”

android:layout_width=”fill_parent”

android:layout_height=”wrap_content”

android:text=”Click to display a dialog” />

3 .        3 . Add the following statements in bold to the MainActivity.java file: package net.learn2develop.Dialog;

import android.app.Activity; import android.os.Bundle; import android.app.AlertDialog; import android.app.Dialog;

import android.content.DialogInterface; import android.view.View;

import android.widget.Button; import android.widget.Toast;

public class MainActivity extends Activity {

CharSequence[] items = { “Google”, “Apple”, “Microsoft” };

boolean[] itemsChecked = new boolean [items.length];

/** Called when the activity is first created. */

@Override

public void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

        setContentView(R.layout.main);

Button btn = (Button) findViewById(R.id.btn_dialog);

btn.setOnClickListener(new View.OnClickListener() {

public void onClick(View v) {

showDialog(0);

}

});

    }

@Override

protected Dialog onCreateDialog(int id) {

switch (id) {

case 0:

return new AlertDialog.Builder(this)

.setIcon(R.drawable.icon)

.setTitle(“This is a dialog with some simple text...”)

.setPositiveButton(“OK”, new

DialogInterface.OnClickListener() {

public void onClick(DialogInterface dialog,

int whichButton)

{

Toast.makeText(getBaseContext(),

“OK clicked!”, Toast.LENGTH_SHORT).show();

}

})

.setNegativeButton(“Cancel”, new

DialogInterface.OnClickListener() {

public void onClick(DialogInterface dialog,

int whichButton)

{

Toast.makeText(getBaseContext(),

“Cancel clicked!”, Toast.LENGTH_SHORT).show();

}

})

3 . 

4 . Press F11 to debug the application on the Android Emulator. Click the button to display the dialog. Checking the various checkboxes will cause the Toast class to display the text of the item checked/unchecked. To dismiss the dialog, click the OK or Cancel button.
how to Display a Dialog Window Using an Activity ?