Posts Tagged ‘Advice’

How to use AlertDialog.Builder in Android applications

Понедельник, Февраль 25th, 2008

DOWNLOAD PROJECT’S SOURCE

It’s a tiny example about an using of alert dialogs (viz, AlertDialog.Builder). If you want to supplement this sample by some material, write me please :)

alertdialogbuilder1.gifalertdialogbuilder2.gif
alertdialogbuilder3.gifalertdialogbuilder4.gif

package maximyudin.AlertDialogBuilderSample;

import android.app.Activity;

import android.os.Bundle;

import android.widget.Button;

import android.view.View;

import android.app.AlertDialog;

import android.content.DialogInterface;

public class AlertDialogBuilderSample extends Activity {

@Override

public void onCreate(Bundle icicle) {

super.onCreate(icicle);

setContentView(R.layout.main);

final Button btnQuit = (Button) findViewById(R.id.btnQuit);

btnQuit.setOnClickListener(new Button.OnClickListener() {

public void onClick(View v) {

new AlertDialog.Builder(AlertDialogBuilderSample.this)

.setTitle(“Question”)

.setMessage(“Are you sure that you want to quit?”)

.setIcon(R.drawable.question)

.setPositiveButton(“Yes”, new DialogInterface.OnClickListener() {

public void onClick(DialogInterface dialog, int whichButton) {

setResult(RESULT_OK);

finish();

}

})

.setNegativeButton(“No”, new DialogInterface.OnClickListener() {

public void onClick(DialogInterface dialog, int whichButton) {

}

})

.show();

}

});

(more…)

Как сделать градиентное окно? [How to make a gradient window?]

Понедельник, Январь 14th, 2008

package maximyudin.gradientsample;

import android.app.Activity;

import android.os.Bundle;

import android.graphics.drawable.GradientDrawable;

import android.graphics.drawable.GradientDrawable.Orientation;

import android.graphics.Color;


public class GradientSample extends Activity {

@Override

public void onCreate(Bundle icicle) {

super.onCreate(icicle);

setContentView(R.layout.main);

GradientDrawable grad =

new GradientDrawable(

Orientation.TOP_BOTTOM,

new int[] {Color.RED, Color.YELLOW}

);

this.getWindow().setBackgroundDrawable(grad);

}

}