Technical Knowledge

technical knowledge is that type of blogger in which you can find all the soluctions of your problems which you cannot solve you can see the video given on this blog and solve your problem by yourself.

Like us on Facebook

Technical Knowledge
Showing posts with label dialog. Show all posts
Showing posts with label dialog. Show all posts

Sunday, March 29, 2015

Custom dialog to take user log in credentials: Android tutorial

Program description:

This program will show how to create a custom dialog which contains 2 edit text boxes to take log in and pass word credentials from user.


First Activity
package com.techpalle.b15_dialogassign;

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

public class MainActivity extends Activity {
Button b;
EditText e1, e2;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
b = (Button) findViewById(R.id.button1);
e1 = (EditText) findViewById(R.id.editText1);
e2 = (EditText) findViewById(R.id.editText2);
b.setOnClickListener(new android.view.View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
showDialog(1);
}
});
}

@Override
protected Dialog onCreateDialog(int id) {
Dialog d = null;
switch(id){
case 1:
AlertDialog.Builder ab = new AlertDialog.Builder(this);
ab.setTitle("Enter user credentials");
ab.setView(getLayoutInflater().
inflate(R.layout.dialog, null));
ab.setPositiveButton("Done", new OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Dialog d = (Dialog) dialog;
EditText x = (EditText) d.findViewById(R.id.editText1);
EditText y = (EditText) d.findViewById(R.id.editText2);
e1.setText(x.getText().toString());
e2.setText(y.getText().toString());
}
});
d = ab.create();
break;
}
return d;
}

}
xml layout file for First Activity 
File name: activity_main.xml

  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" >
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hello_world" />
android:id="@+id/editText1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/textView1"
android:layout_toRightOf="@+id/textView1"
android:ems="10" >


android:id="@+id/editText2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_below="@+id/editText1"
android:ems="10" />



custom xml layout file for Dialog to show log in and password.
File name: dialog.xml

  
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
android:id="@+id/editText1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10" >


android:id="@+id/editText2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10" />



Download complete code : Click to download

More  programs on dialogs:
android Dialogs(alert dialog, datepicker dialog, time picker dialog, progress dialog) tutorial

Tags: android, tutorial, examples, Custom dialog, login dialog, user input dialog

Date picker dialog, and setting the date using onDateSetListener: Android tutorial

Program description:

This program will show how to use date picker dialog. 

This program has 3 edit text boxes to enter year, month, and day. Once user enters date user will click on the button to display the date picker.

It will send year, month, and day to date picker dialog from 3 edit text boxes. On showing date picker dialog, user can change the date. Once user changes the date, then latest date from date picker dialog will be displayed in 3 edit text boxes.


First Activity

package com.techpalle.b15_dialogassignment;

import android.os.Bundle;
import android.app.Activity;
import android.app.DatePickerDialog;
import android.app.Dialog;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.DatePicker;
import android.widget.EditText;

public class MainActivity extends Activity {
//create all the variables..
EditText e1, e2, e3;
Button b;
public static final int DTPKR_DLG = 1; //Constant for date picker dialog

DatePickerDialog.OnDateSetListener lis =
new DatePickerDialog.OnDateSetListener() {
@Override
public void onDateSet(DatePicker view, int year, int monthOfYear,
int dayOfMonth) {
e1.setText(((Integer)year).toString());
e2.setText(""+monthOfYear);
e3.setText(""+dayOfMonth);
}
};

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//initialize all the variables.
e1 = (EditText) findViewById(R.id.editText1);//year
e2 = (EditText) findViewById(R.id.editText2);//month
e3 = (EditText) findViewById(R.id.editText3);//day
b = (Button) findViewById(R.id.button1);
b.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
showDialog(DTPKR_DLG);
}
});
}

@Override
protected void onPrepareDialog(int id, Dialog dialog) {
switch(id){
case DTPKR_DLG:
DatePickerDialog d = (DatePickerDialog) dialog;
String year = e1.getText().toString();
String month = e2.getText().toString();
String day = e3.getText().toString();
break;
}
super.onPrepareDialog(id, dialog);
}

@Override
protected Dialog onCreateDialog(int id) {
Dialog d = null;
switch(id){
case DTPKR_DLG:
String year = e1.getText().toString();
String month = e2.getText().toString();
String day = e3.getText().toString();

DatePickerDialog dp = new DatePickerDialog(this,
lis, Integer.parseInt(year), Integer.parseInt(month),
Integer.parseInt(day));
d = dp;
break;
}
return d;
}

}

xml layout file for first activity
File name : activity_main.xml

  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" >
android:id="@+id/editText1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:ems="10" >


android:id="@+id/editText2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/editText1"
android:layout_below="@+id/editText1"
android:ems="10" />
android:id="@+id/editText3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/editText2"
android:layout_below="@+id/editText2"
android:ems="10" />

Download complete code : Click to download

More  programs on dialogs:
android Dialogs(alert dialog, datepicker dialog, time picker dialog, progress dialog) tutorial
android custom Dialogs tutorial

Tags : datepicker, datepicker dialog, DatePickerDialog.OnDateSetListener, onDateSetListener

Saturday, March 28, 2015

Dialogs in android (alert dialog, date picker, and progress dialog): Android tutorial


Program description:

This program will show how to create a normal alert dialog, items alert dialog, date picker dialog, and progress bar dialog.


There are 4 types of dialogs in android:

1. Alert Dialog
2. Date Picker Dialog
3. Time Picker Dialog
4. Progress Dialog

Alert dialog - is a divided into again 4 types

a. Simple alert dialog - will have title, message, and maximum 3 buttons (yes, no, neutral)
b. items alert dialog  - will have title, items, and maximum 3 buttons
c. Single choice alert dialog - will have title, list of radio items, and maximum 3 buttons.
d. Multi choice alert dialog - will have title, list of check boxes, and maximum 3 buttons.

Date Picker dialog - will show current date, or passed date where use can select a date.

Time Picker dialog - will show current time, and user can select a different time

Progress dialog - which will show progress bar in the dialog.

Progress bar has 2 styles, horizontal progress bar and spinner progress bar.                            Default style is spinner style for progress bar.

Immediately after starting the program, it will show normal alert dialog, from there items, from there progress dialog, and then finally date picker dialog.


First Activity
package co.techpalle.b15_dialogs;

import android.os.Bundle;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.DatePickerDialog;
import android.app.Dialog;
import android.app.ProgressDialog;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.view.Menu;
import android.widget.DatePicker;
import android.widget.Toast;

public class MainActivity extends Activity {
//step1: define constants for dialogs
public static final int NRML_DLG = 1;
public static final int ITMS_DLG = 2;
public static final int PRGRS_DLG = 3;
public static final int DTPKR_DLG = 4;
private DatePickerDialog.OnDateSetListener dpn =
new DatePickerDialog.OnDateSetListener() {
@Override
public void onDateSet(DatePicker view, int year, int monthOfYear,
int dayOfMonth) {

}
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//Step2 : show the normal dialog first.
showDialog(NRML_DLG);
}

//step3 : implement oncreate dialog to create all the dialogs.
@Override
protected Dialog onCreateDialog(int id) {
Dialog d = null;
switch(id){
case NRML_DLG:
//we have to create normal alert dialog
AlertDialog.Builder ab = new AlertDialog.Builder(this);
ab.setTitle("First Dialog");
ab.setIcon(R.drawable.ic_launcher);
ab.setMessage("Do you want to proceed?");
ab.setPositiveButton("Yes", new OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
showDialog(ITMS_DLG);//proceed to next dialog
}
});
ab.setNegativeButton("No", new OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
//..put a toast..
}
});
d = ab.create();
break;

case ITMS_DLG:
//code to create alert items dialog
AlertDialog.Builder ab1 = new AlertDialog.Builder(this);
final CharSequence[] items = {"home", "about us", "contact us"};
ab1.setTitle("Items Dialog");
ab1.setItems(items, new OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Toast.makeText(getApplicationContext(),
items[which], 0).show();
}
});
ab1.setPositiveButton("Proceed", new OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
showDialog(PRGRS_DLG);
}
});
d = ab1.create();
break;

case PRGRS_DLG:
//code to create progress dialog
ProgressDialog p = new ProgressDialog(this);
p.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
p.setProgress(30);
p.setButton("Go next", new OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
showDialog(DTPKR_DLG);
}
});
d = p;
break;

case DTPKR_DLG:
//code to create date picker dialog
DatePickerDialog dp = new DatePickerDialog(this,
null, 2013, 6, 1);//year month day
d = dp;
break;
}
return d;
}

}




xml layout file for First Activity 
File name: activity_main.xml

  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" >
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hello_world" />


Download complete code : Click to download

More  programs on dialogs:
android custom Dialogs tutorial

Tags: android, dialog, alert dialog, custom dialog, date picker dialog, items dialog, progress dialog, tutorial, examples

Monday, March 23, 2015

Date picker dialog, and setting the date using onDateSetListener: Android tutorial

Program description:

This program will show how to use date picker dialog. 

This program has 3 edit text boxes to enter year, month, and day. Once user enters date user will click on the button to display the date picker.

It will send year, month, and day to date picker dialog from 3 edit text boxes. On showing date picker dialog, user can change the date. Once user changes the date, then latest date from date picker dialog will be displayed in 3 edit text boxes.


First Activity

package com.techpalle.b15_dialogassignment;

import android.os.Bundle;
import android.app.Activity;
import android.app.DatePickerDialog;
import android.app.Dialog;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.DatePicker;
import android.widget.EditText;

public class MainActivity extends Activity {
//create all the variables..
EditText e1, e2, e3;
Button b;
public static final int DTPKR_DLG = 1; //Constant for date picker dialog

DatePickerDialog.OnDateSetListener lis =
new DatePickerDialog.OnDateSetListener() {
@Override
public void onDateSet(DatePicker view, int year, int monthOfYear,
int dayOfMonth) {
e1.setText(((Integer)year).toString());
e2.setText(""+monthOfYear);
e3.setText(""+dayOfMonth);
}
};

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//initialize all the variables.
e1 = (EditText) findViewById(R.id.editText1);//year
e2 = (EditText) findViewById(R.id.editText2);//month
e3 = (EditText) findViewById(R.id.editText3);//day
b = (Button) findViewById(R.id.button1);
b.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
showDialog(DTPKR_DLG);
}
});
}

@Override
protected void onPrepareDialog(int id, Dialog dialog) {
switch(id){
case DTPKR_DLG:
DatePickerDialog d = (DatePickerDialog) dialog;
String year = e1.getText().toString();
String month = e2.getText().toString();
String day = e3.getText().toString();
break;
}
super.onPrepareDialog(id, dialog);
}

@Override
protected Dialog onCreateDialog(int id) {
Dialog d = null;
switch(id){
case DTPKR_DLG:
String year = e1.getText().toString();
String month = e2.getText().toString();
String day = e3.getText().toString();

DatePickerDialog dp = new DatePickerDialog(this,
lis, Integer.parseInt(year), Integer.parseInt(month),
Integer.parseInt(day));
d = dp;
break;
}
return d;
}

}

xml layout file for first activity
File name : activity_main.xml

  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" >
android:id="@+id/editText1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:ems="10" >


android:id="@+id/editText2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/editText1"
android:layout_below="@+id/editText1"
android:ems="10" />
android:id="@+id/editText3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/editText2"
android:layout_below="@+id/editText2"
android:ems="10" />

Download complete code : Click to download

More  programs on dialogs:
android Dialogs(alert dialog, datepicker dialog, time picker dialog, progress dialog) tutorial
android custom Dialogs tutorial

Tags : datepicker, datepicker dialog, DatePickerDialog.OnDateSetListener, onDateSetListener

Custom dialog to take user log in credentials: Android tutorial

Program description:

This program will show how to create a custom dialog which contains 2 edit text boxes to take log in and pass word credentials from user.


First Activity
package com.techpalle.b15_dialogassign;

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

public class MainActivity extends Activity {
Button b;
EditText e1, e2;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
b = (Button) findViewById(R.id.button1);
e1 = (EditText) findViewById(R.id.editText1);
e2 = (EditText) findViewById(R.id.editText2);
b.setOnClickListener(new android.view.View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
showDialog(1);
}
});
}

@Override
protected Dialog onCreateDialog(int id) {
Dialog d = null;
switch(id){
case 1:
AlertDialog.Builder ab = new AlertDialog.Builder(this);
ab.setTitle("Enter user credentials");
ab.setView(getLayoutInflater().
inflate(R.layout.dialog, null));
ab.setPositiveButton("Done", new OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Dialog d = (Dialog) dialog;
EditText x = (EditText) d.findViewById(R.id.editText1);
EditText y = (EditText) d.findViewById(R.id.editText2);
e1.setText(x.getText().toString());
e2.setText(y.getText().toString());
}
});
d = ab.create();
break;
}
return d;
}

}
xml layout file for First Activity 
File name: activity_main.xml

  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" >
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hello_world" />
android:id="@+id/editText1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/textView1"
android:layout_toRightOf="@+id/textView1"
android:ems="10" >


android:id="@+id/editText2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_below="@+id/editText1"
android:ems="10" />



custom xml layout file for Dialog to show log in and password.
File name: dialog.xml

  
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
android:id="@+id/editText1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10" >


android:id="@+id/editText2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10" />



Download complete code : Click to download

More  programs on dialogs:
android Dialogs(alert dialog, datepicker dialog, time picker dialog, progress dialog) tutorial

Tags: android, tutorial, examples, Custom dialog, login dialog, user input dialog

Dialogs in android (alert dialog, date picker, and progress dialog): Android tutorial


Program description:

This program will show how to create a normal alert dialog, items alert dialog, date picker dialog, and progress bar dialog.


There are 4 types of dialogs in android:

1. Alert Dialog
2. Date Picker Dialog
3. Time Picker Dialog
4. Progress Dialog

Alert dialog - is a divided into again 4 types

a. Simple alert dialog - will have title, message, and maximum 3 buttons (yes, no, neutral)
b. items alert dialog  - will have title, items, and maximum 3 buttons
c. Single choice alert dialog - will have title, list of radio items, and maximum 3 buttons.
d. Multi choice alert dialog - will have title, list of check boxes, and maximum 3 buttons.

Date Picker dialog - will show current date, or passed date where use can select a date.

Time Picker dialog - will show current time, and user can select a different time

Progress dialog - which will show progress bar in the dialog.

Progress bar has 2 styles, horizontal progress bar and spinner progress bar.                            Default style is spinner style for progress bar.

Immediately after starting the program, it will show normal alert dialog, from there items, from there progress dialog, and then finally date picker dialog.


First Activity
package co.techpalle.b15_dialogs;

import android.os.Bundle;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.DatePickerDialog;
import android.app.Dialog;
import android.app.ProgressDialog;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.view.Menu;
import android.widget.DatePicker;
import android.widget.Toast;

public class MainActivity extends Activity {
//step1: define constants for dialogs
public static final int NRML_DLG = 1;
public static final int ITMS_DLG = 2;
public static final int PRGRS_DLG = 3;
public static final int DTPKR_DLG = 4;
private DatePickerDialog.OnDateSetListener dpn =
new DatePickerDialog.OnDateSetListener() {
@Override
public void onDateSet(DatePicker view, int year, int monthOfYear,
int dayOfMonth) {

}
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//Step2 : show the normal dialog first.
showDialog(NRML_DLG);
}

//step3 : implement oncreate dialog to create all the dialogs.
@Override
protected Dialog onCreateDialog(int id) {
Dialog d = null;
switch(id){
case NRML_DLG:
//we have to create normal alert dialog
AlertDialog.Builder ab = new AlertDialog.Builder(this);
ab.setTitle("First Dialog");
ab.setIcon(R.drawable.ic_launcher);
ab.setMessage("Do you want to proceed?");
ab.setPositiveButton("Yes", new OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
showDialog(ITMS_DLG);//proceed to next dialog
}
});
ab.setNegativeButton("No", new OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
//..put a toast..
}
});
d = ab.create();
break;

case ITMS_DLG:
//code to create alert items dialog
AlertDialog.Builder ab1 = new AlertDialog.Builder(this);
final CharSequence[] items = {"home", "about us", "contact us"};
ab1.setTitle("Items Dialog");
ab1.setItems(items, new OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Toast.makeText(getApplicationContext(),
items[which], 0).show();
}
});
ab1.setPositiveButton("Proceed", new OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
showDialog(PRGRS_DLG);
}
});
d = ab1.create();
break;

case PRGRS_DLG:
//code to create progress dialog
ProgressDialog p = new ProgressDialog(this);
p.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
p.setProgress(30);
p.setButton("Go next", new OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
showDialog(DTPKR_DLG);
}
});
d = p;
break;

case DTPKR_DLG:
//code to create date picker dialog
DatePickerDialog dp = new DatePickerDialog(this,
null, 2013, 6, 1);//year month day
d = dp;
break;
}
return d;
}

}




xml layout file for First Activity 
File name: activity_main.xml

  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" >
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hello_world" />


Download complete code : Click to download

More  programs on dialogs:
android custom Dialogs tutorial

Tags: android, dialog, alert dialog, custom dialog, date picker dialog, items dialog, progress dialog, tutorial, examples

Older Posts Home