NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io

MainActivity.java

package cmc_android_course.app296_dialogboxes;

import android.app.AlertDialog;
import android.app.Dialog;
import android.app.ProgressDialog;
import android.content.DialogInterface;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Toast;
import static cmc_android_course.app296_dialogboxes.R.id.icon;


public class MainActivity extends ActionBarActivity {
CharSequence items[]={"A","B","C","D","E"};
boolean status[]={true,false,true,false,true};

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

@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}

public void showSimple(View v)
{
showDialog(1);
}
public void showMultichoice(View v){
showDialog(2);
}
public void showProgress(View v){
showDialog(3);

}
@Override
protected Dialog onCreateDialog(int id, Bundle args)
{
switch (id)
{
case 1: AlertDialog.Builder b1=new AlertDialog.Builder(this);

b1.setIcon(icon);
b1.setTitle("Simple Dialog Box Demo");
b1.setMessage("Choose an option");
b1.setCancelable(false);
b1.setNegativeButton("OK", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Toast.makeText(getApplicationContext(), "OK button pressed", Toast.LENGTH_LONG).show();
}
});
b1.setPositiveButton("CANCEL", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Toast.makeText(getApplicationContext(), "Cancel button pressed", Toast.LENGTH_SHORT).show();
}
});
return b1.create();

case 2:
AlertDialog.Builder b2=new AlertDialog.Builder(this);
b2.setIcon(R.id.image);
b2.setTitle("Multichoice Dialog Box Demo");
b2.setCancelable(false);
b2.setMessage("Choose appropriate option from the following");
b2.setMultiChoiceItems(items, status, new DialogInterface.OnMultiChoiceClickListener() {
@Override
public void onClick(DialogInterface dialog, int which, boolean isChecked) {
CharSequence item = items[which];
boolean st=status[which];

// Log.d("MainActivity", String.format("%s: %s", items[which], isChecked));

// if(isChecked)
// {
// CharSequence item = items[which];
String res=st==true ? "CHECKED" : "UNCHECKED";
Toast.makeText(getApplicationContext(),item+" "+res, Toast.LENGTH_SHORT).show();
// }
}
});
b2.setNegativeButton("OK", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Toast.makeText(getApplicationContext(), "OK button pressed", Toast.LENGTH_LONG).show();
}
});
b2.setPositiveButton("CANCEL", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Toast.makeText(getApplicationContext(), "Cancel button pressed", Toast.LENGTH_SHORT).show();
}
});
return b2.create();

case 3:
final ProgressDialog pd=new ProgressDialog(this);
pd.setMessage("DOWNLOADING IN PROGRESS");
pd.setCancelable(false);
pd.setTitle("Progress Dialog Box Demo");
pd.setIcon(R.drawable.abc_btn_check_material);
pd.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
pd.setButton("Cancel", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {

Toast.makeText(getApplicationContext(), "Downloading cancelled", Toast.LENGTH_SHORT).show();
}
});

return pd;
default: break;
}
return super.onCreateDialog(id, args);
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {

int id = item.getItemId();

if (id == R.id.action_settings) {
return true;
}

return super.onOptionsItemSelected(item);
}
}









activity_main.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:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity">

<Button
android:layout_width="90dp"
android:layout_height="90dp"
android:text="Simple"
android:id="@+id/button"
android:background="@android:color/holo_blue_light"
android:onClick="showSimple"
android:layout_alignParentTop="true"
android:layout_alignLeft="@+id/button2"
android:layout_alignStart="@+id/button2" />

<Button
android:layout_width="95dp"
android:layout_height="95dp"
android:text="Multichoice"
android:id="@+id/button2"
android:background="@android:color/holo_red_light"
android:onClick="showMultichoice"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"/>

<Button
android:layout_width="90dp"
android:layout_height="90dp"
android:text="Progress"
android:id="@+id/button3"
android:background="@android:color/holo_green_dark"
android:onClick="showProgress"
android:layout_alignParentBottom="true"
android:layout_alignLeft="@+id/button2"
android:layout_alignStart="@+id/button2" />

<ProgressBar
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/progressBar"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_alignTop="@+id/button3"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:max="100"
android:indeterminate="false" />
</RelativeLayout>
     
 
what is notes.io
 

Notes.io is a web-based application for taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000 notes created and continuing...

With notes.io;

  • * You can take a note from anywhere and any device with internet connection.
  • * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
  • * You can quickly share your contents without website, blog and e-mail.
  • * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
  • * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.

Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.

Easy: Notes.io doesn’t require installation. Just write and share note!

Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )

Free: Notes.io works for 12 years and has been free since the day it was started.


You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;


Email: [email protected]

Twitter: http://twitter.com/notesio

Instagram: http://instagram.com/notes.io

Facebook: http://facebook.com/notesio



Regards;
Notes.io Team

     
 
Shortened Note Link
 
 
Looding Image
 
     
 
Long File
 
 

For written notes was greater than 18KB Unable to shorten.

To be smaller than 18KB, please organize your notes, or sign in.