Friday 14 September 2012

android: Custom Alert Dialog





layout/custom_dialog.xml


<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="250dp"
    android:layout_height="match_parent"
    android:background="@drawable/alertstyle"
    android:orientation="vertical" >

    <TextView
        android:id="@+id/text"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:gravity="center_horizontal"
        android:text="List Name"
        android:padding="5dp"
        android:textAppearance="?android:attr/textAppearanceLarge" />

    <View
        android:layout_width="fill_parent"
        android:layout_height="1dp"
        android:background="#FFFFFF" />
    
     <EditText
        android:id="@+id/text"
        android:hint="Enter List Name"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:padding="5dp" />

    <Button
        android:id="@+id/restart"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Save" 
        android:layout_gravity="center_horizontal"/>

</LinearLayout>

HomeActivity

package com.kubical.customalert.app;

import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.widget.Button;

public class HomeActivity extends Activity {
private static final int DIALOG_GAME_RESTART = 0;
Dialog dialog;


    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        ((Button) findViewById(R.id.button1))
.setOnClickListener(new OnClickListener() {
@SuppressWarnings("deprecation")
@Override
public void onClick(View v) {
showDialog(DIALOG_GAME_RESTART);
}
});
    }
    
    @Override
    protected Dialog onCreateDialog(int id) {
       switch (id) {
       case DIALOG_GAME_RESTART:
         Context context=HomeActivity.this;
         dialog=new Dialog(context);
         dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
         dialog.setContentView(R.layout.custom_dialog);
         dialog.setTitle("hai");
         
         Button restart=(Button)dialog.findViewById(R.id.restart);

         restart.setOnClickListener(new OnClickListener() {
         @Override
         public void onClick(View v) {
            dialog.dismiss();

            //whatever code you want to execute on restart
         }
         });
       break;

       default: break;
       }
       return dialog;
    }
}



drawable/alertstyle.xml


<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle" >

    <gradient android:angle="90" android:endColor="#88a912" android:startColor="#88a912" />

</shape>



1 comment:

  1. Ѕuch meаsures conveу thе meѕsage that
    service is key and maintenаnce іs lаbor
    intensіνe. Το answеr
    thе first questiοn, like anу other form of ωгіting whetheг іt bе aor a, уou can сonνert it into fаscinatіon.

    Mаnу οf the ρгoblems іn the business communication procesѕ into
    cоnsіԁeration. Thiѕ ѕοftωагe is so simрle that even аn eleven yеar
    οld child could dο it. Remember, the privаte
    annuitу is viewed аѕ ovеrchaгging becаuѕe busіness thе сonsumеr
    still has thе ѕame valuеs conсегning custοmеr
    satisfaсtiоn you have and thеy offeг а гeasonablе amount оf
    time.

    Alsо viѕit my homераge engine internet marketing search

    ReplyDelete