Saturday 29 December 2012

Jquery Mobile: Filtered List - only match beginning of string


$("document").ready( function (){
function beginsWith( text, pattern) {
text= text.toLowerCase();
pattern = pattern.toLowerCase();
return pattern != text.substr( 0, pattern.length );
}
 $(".ui-listview").listview('option', 'filterCallback', beginsWith)

});

Friday 21 December 2012

android: Intent


Intent intent = new Intent(this, Main.class);
startActivity(intent);

android: Intent clear flags

intent1.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

android: Count down timer


int timer = b.getInt("time", 0);                                      

new CountDownTimer(timer, 500) {

@Override
public void onTick(long millisUntilFinished) {
tv1.setText("Sec Left:" + millisUntilFinished / 1000 + " ");

// TODO Auto-generated method stub

}

Thursday 20 December 2012

android: Getting source code from an APK file


Step 1:

Make a new folder and put .apk file (which you want to decode) now rename this .apk file with extension .zip (eg:rename from filename.apk to filename.apk.zip) and save it..now you get classes.dex files etc...at this stage you are able to see drawable but not xml and java file...so cont...

Step 2:

Now extract this zip apk file in the same folder(in this eg or case NEW FOLDER). now dowmload dex2jar from this link http://code.google.com/p/dex2jar/ and extract it to the same folder (in this case NEW FOLDER).....now open command prompt and reach to that folder (in this case NEW FOLDER)....after reaching write dex2jar classes.dex and press enter.....now you get classes.dex.dex2jar file in the same folder......now download java decompiler from http://java.decompiler.free.fr/?q=jdgui and now double click on jd-gui and click on open file then open classes.dex.dex2jar file from that folder...now you get class file...save all these class file (click on file then click "save all sources" in jd-gui)..by src name....at this stage you get source...but xml files are still unreadable...so cont...

Step 3:

Now open another new folder and put these files
  1. put .apk file which you want to decode
  2. download apktool v1.x AND apktool install window using google and put in the same folder
  3. download framework-res.apk file using google and put in the same folder (Not all apk file need framework-res.apk file)
  4. Open a command window
  5. Navigate to the root directory of APKtool and type the following command: apktool if framework-res.apk
  6. apktool d "fname".apk ("fname" denotes filename which you want to decode)
now you get a file folder in that folder and now you can easily read xml files also.

Step 4:

It's not any step just copy contents of both folder(in this case both new folder)to the single one

Thursday 13 December 2012

android: Showing keypad moves layout up

android:windowSoftInputMode="adjustResize"

add this to the activity in the manifest file

Wednesday 12 December 2012

android: User Current location

Note: Enable your provider


locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
// Define the criteria how to select the locatioin provider -> use
// default
Criteria criteria = new Criteria();
provider = locationManager.getBestProvider(criteria, false);
Location location = locationManager.getLastKnownLocation(provider);

if (location != null) {
System.out.println("Provider " + provider + " has been selected.");

} else {
Toast.makeText(this, "Provider not available",
Toast.LENGTH_SHORT).show();
}

double lat = location.getLatitude();
double lng = location.getLongitude();
String addressString = "no address found";
           Geocoder gc = new Geocoder(this, Locale.getDefault());
           try
           {
               List<Address> addresses = gc.getFromLocation(lat,
                       lng, 1);
               StringBuilder sb = new StringBuilder();
               if (addresses.size() > 0)
               {
                   address = (Address) addresses.get(0);
                   sb.append(address.getLocality());
               }
               addressString = sb.toString();
           
           } catch (Exception e)
           {
           }
           Toast.makeText(this,"Your Current Location is :"+String.valueOf(addressString),
    Toast.LENGTH_SHORT).show();
           System.out.println(String.valueOf(addressString));
                   Toast.makeText(this,address.getLocality(),
     Toast.LENGTH_SHORT).show();

android: android with SOAP webservice interaction.

Android:


import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapPrimitive;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;

import android.app.Activity;
import android.os.Bundle;
import android.text.Editable;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;
import android.widget.Toast;

public class Registration extends Activity {
private String METHOD_NAME ="insertRegistrationData";
private String NAMESPACE ="http://DefaultNamespace";
private String SOAP_ACTION ="RegistrationDataService";
private static final String URL="http://192.168.2.7:8080/AptbusServer/services/RegistrationData";
EditText pname,address,zip,birth;
TextView newpatient,exist;
RadioButton pnew,exis;
Button button;
private RadioGroup choice;
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        pname=(EditText)findViewById(R.id.pname);
        address=(EditText)findViewById(R.id.address);
        zip=(EditText)findViewById(R.id.zip);
        birth=(EditText)findViewById(R.id.birth);
        choice=(RadioGroup)findViewById(R.id.ptype);
        pnew=(RadioButton)findViewById(R.id.newpatient);
        exis=(RadioButton)findViewById(R.id.exist);
        button=(Button)findViewById(R.id.next);
        button.setOnClickListener(new OnClickListener(){
        String radio=null;
@Override
public void onClick(View v) {
   
Editable patientname=pname.getText();
       String patname=patientname.toString();
     
       Editable addr=address.getText();
       String paddr=addr.toString();
     
       Editable zipco=zip.getText();
       String pzip=zipco.toString();
       int pzipcode=Integer.parseInt(pzip);
     
       Editable pbirth=birth.getText();
       String pbirthdate=pbirth.toString();
       if(pnew.isChecked())
       {
        radio=(String) pnew.getText();
       }
       if(exis.isChecked())
       {
        radio=(String) exis.getText();
       }
     
       Toast.makeText(getApplicationContext(),
                            patname+""+ paddr+""+ pzip+""+pbirthdate+""+radio, Toast.LENGTH_LONG).show();
       try
       {
        SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
        request.addProperty("s",patname);
        request.addProperty("s1",paddr);
        request.addProperty("zip",pzipcode);
        request.addProperty("gender",radio);
        request.addProperty("dat",pbirthdate);
        SoapSerializationEnvelope soapEnvelope = new SoapSerializationEnvelope(
SoapEnvelope.VER11);
soapEnvelope.setOutputSoapObject(request);
HttpTransportSE androidHttpTransport = new HttpTransportSE(
URL);
androidHttpTransport.call(SOAP_ACTION, soapEnvelope);
SoapPrimitive resultsRequestSOAP = (SoapPrimitive) soapEnvelope
.getResponse();
String result = resultsRequestSOAP.toString();
System.out.println("Result : " + result);
       
       }
       catch(Exception e)
       {
        System.out.println(e);
       }
   
     
}
       
        });
     
       
   
    }
}

SOAP:

<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions targetNamespace="http://DefaultNamespace" xmlns:apachesoap="http://xml.apache.org/xml-soap" xmlns:impl="http://DefaultNamespace" xmlns:intf="http://DefaultNamespace" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:wsdlsoap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<!--WSDL created by Apache Axis version: 1.4
Built on Apr 22, 2006 (06:55:48 PDT)-->
 <wsdl:types>
  <schema elementFormDefault="qualified" targetNamespace="http://DefaultNamespace" xmlns="http://www.w3.org/2001/XMLSchema">
   <element name="insertRegistrationData">
    <complexType>
     <sequence>
      <element name="s" type="xsd:string"/>
      <element name="s1" type="xsd:string"/>
      <element name="zip" type="xsd:int"/>
      <element name="gender" type="xsd:string"/>
      <element name="dat" type="xsd:string"/>
     </sequence>
    </complexType>
   </element>
   <element name="insertRegistrationDataResponse">
    <complexType>
     <sequence>
      <element name="insertRegistrationDataReturn" type="xsd:int"/>
     </sequence>
    </complexType>
   </element>
  </schema>
 </wsdl:types>

   <wsdl:message name="insertRegistrationDataResponse">

      <wsdl:part element="impl:insertRegistrationDataResponse" name="parameters">

      </wsdl:part>

   </wsdl:message>

   <wsdl:message name="insertRegistrationDataRequest">

      <wsdl:part element="impl:insertRegistrationData" name="parameters">

      </wsdl:part>

   </wsdl:message>

   <wsdl:portType name="RegistrationData">

      <wsdl:operation name="insertRegistrationData">

         <wsdl:input message="impl:insertRegistrationDataRequest" name="insertRegistrationDataRequest">

       </wsdl:input>

         <wsdl:output message="impl:insertRegistrationDataResponse" name="insertRegistrationDataResponse">

       </wsdl:output>

      </wsdl:operation>

   </wsdl:portType>

   <wsdl:binding name="RegistrationDataSoapBinding" type="impl:RegistrationData">

      <wsdlsoap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>

      <wsdl:operation name="insertRegistrationData">

         <wsdlsoap:operation soapAction=""/>

         <wsdl:input name="insertRegistrationDataRequest">

            <wsdlsoap:body use="literal"/>

         </wsdl:input>

         <wsdl:output name="insertRegistrationDataResponse">

            <wsdlsoap:body use="literal"/>

         </wsdl:output>

      </wsdl:operation>

   </wsdl:binding>

   <wsdl:service name="RegistrationDataService">

      <wsdl:port binding="impl:RegistrationDataSoapBinding" name="RegistrationData">

         <wsdlsoap:address location="http://localhost:8080/AptbusServer/services/RegistrationData"/>

      </wsdl:port>

   </wsdl:service>

</wsdl:definitions>


android: alphabet indexer / display alphabets while scrolling.


class MyCursorAdapter extends SimpleCursorAdapter implements SectionIndexer {

AlphabetIndexer alphaIndexer;

public MyCursorAdapter(Context context, int layout, Cursor c,
String[] from, int[] to) {

super(context, layout, c, from, to);

alphaIndexer = new AlphabetIndexer(c,
c.getColumnIndex(Dbasehelper.COL_WORD),
" ABCDEFGHIJKLMNOPQRSTUVWXYZ");
}

@Override
public int getPositionForSection(int section) {

return alphaIndexer.getPositionForSection(section); // use the
// indexer

}

@Override
public int getSectionForPosition(int position) {

return alphaIndexer.getSectionForPosition(position); // use the
// indexer

}

@Override
public Object[] getSections() {

return alphaIndexer.getSections(); // use the indexer

}

}

Tuesday 11 December 2012

android: SharedPreference to compare dates.


 int thisDay = c.get(Calendar.DAY_OF_YEAR);
       
        SharedPreferences prefs = this.getSharedPreferences(
             "tempstore", Context.MODE_PRIVATE);
        int l = prefs.getInt("tempstore", 23);
        if(l != thisDay){
        Toast.makeText(getApplicationContext(), "not equal", Toast.LENGTH_SHORT).show();
        prefs.edit().putInt("tempstore", thisDay).commit();
        }

Tuesday 4 December 2012

android: menus


private static final int MENU_HELP = 0;
private static final int MENU_ABOUT = 1;
private static final int MENU_EXIT = 2;


public boolean onCreateOptionsMenu(Menu menu) {
menu.add(0, MENU_HELP, 0, "Help").setIcon(R.drawable.help);
menu.add(0, MENU_ABOUT, 0, "About").setIcon(R.drawable.about);
menu.add(0, MENU_EXIT, 0, "exit").setIcon(R.drawable.exit);
return true;
}


public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case MENU_HELP:
startActivity(new Intent(this, Help.class));
return true;
case MENU_ABOUT:
startActivity(new Intent(this, About.class));
return true;
case MENU_EXIT:
System.exit(0);
finish();
return true;
default:
return super.onOptionsItemSelected(item);
}
}

android: Preventing WebView reload on Rotation


HelloWebView.java

public class HelloWebView extends Activity {
WebView webview;

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.webview);
webview = (WebView) findViewById(R.id.webview);
webview.getSettings().setJavaScriptEnabled(true);
if (savedInstanceState == null)
{
webview.loadUrl(" http://www.google.com");
}
webview.setWebViewClient(new HelloWebViewClient());

}

@Override
protected void onSaveInstanceState(Bundle outState )
{
super.onSaveInstanceState(outState);
webview.saveState(outState);
}

@Override
protected void onRestoreInstanceState(Bundle savedInstanceState)
{
super.onSaveInstanceState(savedInstanceState);
webview.restoreState(savedInstanceState);
}

public class HelloWebViewClient extends WebViewClient {
ProgressDialog progressBar = ProgressDialog.show(HelloWebView.this, "Loading", "Please wait...");

@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}

@Override
public void onPageFinished(WebView view, String url) {
if (progressBar.isShowing()) {
                 progressBar.dismiss();
             }
}
}

webview.xml


<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical">

    <WebView
        android:id="@+id/webview"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
    />

</LinearLayout>


Wednesday 28 November 2012

Jquery Mobile: Get selected text from dropdownlist

("#id option:selected").text();

Jquery Mobile: Time picker




<div data-role="fieldcontain">
<fieldset data-role="controlgroup" data-type="horizontal">
<legend>Select From Time:</legend>

<select
name="select-choice-month" id="fromtime">
<option>Hrs</option>
<option value="1">00</option>
<option value="2">01</option>
<option value="3">02</option>
<option value="4">03</option>
<option value="5">04</option>
<option value="6">05</option>
<option value="7">06</option>
<option value="8">07</option>
<option value="9">08</option>
<option value="10">09</option>
<option value="11">10</option>
<option value="12">11</option>
<option value="13">12</option>
<option value="14">13</option>
<option value="15">14</option>
<option value="16">15</option>
<option value="17">16</option>
<option value="18">17</option>
<option value="19">18</option>
<option value="20">19</option>
<option value="21">20</option>
<option value="22">21</option>
<option value="23">22</option>
<option value="24">23</option>
</select>
<select
name="select-choice-day" id="select-choice-day">
<option>Min</option>
<option value="1">:00</option>
<option value="1">:05</option>
<option value="1">:10</option>
<option value="1">:15</option>
<option value="1">:20</option>
<option value="1">:25</option>
<option value="1">:30</option>
<option value="1">:35</option>
<option value="1">:40</option>
<option value="1">:45</option>
<option value="1">:50</option>
<option value="1">:55</option>
</select>
</fieldset>
</div>


Saturday 17 November 2012

Jquery Mobile: .focus()

http://jquerymobile.com/demos/1.0a2/experiments/api-viewer/docs/focus/index.html

Jquery Mobile: Disable Buttons in jQuery Mobile


var clicked = false;

$('#myButton').click(function() {
    if(clicked === false) {
        $(this).addClass('ui-disabled');
        clicked = true;
        alert('Button is now disabled');
    } 
});

$('#enableButton').click(function() {
    $('#myButton').removeClass('ui-disabled');
    clicked = false; 
});
HTML
<div data-role="page" id="home">
    <div data-role="content">

        <a href="#" data-role="button" id="myButton">Click button</a>
        <a href="#" data-role="button" id="enableButton">Enable button</a>

    </div>
</div>

http://jquerymobile.com/demos/1.0.1/docs/forms/docs-forms.html

Jquery Mobile: How to create Toast Message


$("<div  style='background-color: white' class='ui-loader ui-overlay-shadow ui-body-e ui-corner-all'><h1>Enter From Location</h1></div>").css({ "display": "block", "opacity": 0.96, "top": $(window).scrollTop() + 300 })  .appendTo( $.mobile.pageContainer )
.delay( 1500 ) .fadeOut( 400, function(){ $(this).remove();
  });

android: How to open android adb from command prompt?


In the command prompt Go to this path or set as classpath F:\PROJECTS\ANDROID\android-sdk_r10-windows\android-sdk-windows\platform-tools

Then type

adb shell
u will see:

#
Type

# sqlite3 /data/data/com.yourpackage/databases/yourdbname

Monday 22 October 2012

android: toggle and switch buttons


 <ToggleButton
            android:id="@+id/switchitem"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@drawable/toggle"
            android:checked="true" 
            android:textOn=""
            android:textOff=""/>

and the drawable will be :
toggle_me_on.png

toggle_me_off.png

<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_checked="true"
        android:drawable="@drawable/toggle_me_on" /> <!-- pressed -->
    <item android:drawable="@drawable/toggle_me_off" /> <!-- default/unchecked -->
</selector>

android: Long string in ListView's items


android:singleLine="true"
android:ellipsize="end"

android: How to make keypad hidden when the activity is started

getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);

Friday 19 October 2012

android: How to erase Activity stack in Android?

intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
or 
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

Monday 15 October 2012

android: can't call String.isEmpty()


Use String.length() == 0 instead. It is backwards compatible all the way back to JDK 1.0 ... and with J2ME as well.
String.equals("") is another alternative.

android: Develop Android's application for all the versions

In Manifest file just add


<uses-sdk android:minSdkVersion="8" android:targetSdkVersion="10">

Wednesday 10 October 2012

android: Manually Select the Spinner Item


Spinner s = (Spinner) findViewById(R.id.spinner_id);
int i = adapter.getPosition("blue");
s.setSelection(i);

Saturday 29 September 2012

android: How to make first letter capital in String

String s = "hello";
Integer x = s.length();
String s2 = s.substring(0,1).toUpperCase().concat(s.substring(1, x));

Wednesday 26 September 2012

android: Alert Dialog with two buttons


AlertDialog.Builder builder2=new AlertDialog.Builder(MyAlertdialogActivity.this);
  builder2.setMessage("Do you want to continue");
  builder2.setPositiveButton("Yes",new DialogInterface.OnClickListener() {

  @Override
   public void onClick(DialogInterface dialog, int which) {

// TODO Auto-generated method stub

  Toast.makeText(getApplicationContext(), "U Clicked OK", Toast.LENGTH_LONG).show();

  }

  });

  builder2.setNegativeButton("No", new DialogInterface.OnClickListener() {

@Override
  
  public void onClick(DialogInterface dialog, int which) {

// TODO Auto-generated method stub

  Toast.makeText(getApplicationContext(), "U Clicked Cancel ", Toast.LENGTH_LONG).show();

  }

  });

  builder2.show();

android: AutoCompleteTextView with addTextChangedListener


 public class CountriesActivity extends Activity {
     protected void onCreate(Bundle icicle) {
         super.onCreate(icicle);
         setContentView(R.layout.countries);

         ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
                 android.R.layout.simple_dropdown_item_1line, COUNTRIES);
         AutoCompleteTextView textView = (AutoCompleteTextView)
                 findViewById(R.id.countries_list);
         textView.setAdapter(adapter); 
textView.addTextChangedListener(new TextWatcher() {
    
 @Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
 if(adapter.getCount() == 0) {
Toast.makeText(getApplicationContext(), "Adapter : 0", Toast.LENGTH_SHORT).show();
    }
     
  }
    
 @Override
public void beforeTextChanged(CharSequence s, int start, int count,
      int after) {
// TODO Auto-generated method stub
     
    }
    
   
@Override
public void afterTextChanged(Editable s) {
     
    }
   });
     }

     private static final String[] COUNTRIES = new String[] {
         "Belgium", "France", "Italy", "Germany", "Spain"
     };
 }

Monday 24 September 2012

android: Add params to already existing View in the XML


 CheckBox cb12=(CheckBox)child.findViewById(R.id.subtext);
 RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams)cb12.getLayoutParams();
  params.setMargins(37, 0, 0, 0);
 cb12.setLayoutParams(params);

Sunday 23 September 2012

android: Splash screen


Splash.java

public class Splash extends Activity {
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
LayoutInflater inflater = getLayoutInflater();
View layout = inflater.inflate(R.layout.splashscreen,
(ViewGroup) findViewById(R.id.splash));
Toast toast = new Toast(getApplicationContext());
toast.setGravity(Gravity.CENTER_VERTICAL, 0, 0);
toast.setDuration(Toast.LENGTH_LONG);
toast.setView(layout);
toast.show();


new Handler().post(new Runnable() {
@Override
public void run() {
Splash.this.startActivity(new Intent(Splash.this,
MainActivity.class));
Splash.this.finish();
}
});


}
}

splashscreen.xml 


<?xml version="1.0" encoding="utf-8"?>
<FrameLayout android:id="@+id/splash"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="fill_parent">
<ImageView android:id="@+id/splashscreen"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:src="@drawable/splashbig" android:scaleType="fitXY"
android:layout_gravity="center" />
</FrameLayout>

android: Dynamic Menus with out XML


private static final int MENU_EDITLIST = 0;
private static final int MENU_HELP = 1;
private static final int MENU_ABOUT = 2;


public boolean onCreateOptionsMenu(Menu menu) {
menu.add(0, MENU_EDITLIST, 0, "Edit List").setIcon(
R.drawable.ic_launcher);
menu.add(0, MENU_HELP, 0, "Help").setIcon(R.drawable.ic_launcher);
menu.add(0, MENU_ABOUT, 0, "About us").setIcon(R.drawable.ic_launcher);
return true;
}


public boolean onOptionsItemSelected(MenuItem item) {

switch (item.getItemId()) {
case MENU_EDITLIST:
Intent intent1 = new Intent(this, Help.class);
startActivity(intent1);
return true;
case MENU_HELP:
Intent intent1 = new Intent(this, Help.class);
startActivity(intent1);
return true;
case MENU_ABOUT:
Intent intent2 = new Intent(this, About.class);
startActivity(intent2);
return true;
default:
return super.onOptionsItemSelected(item);
}
}


android: Capture the BACK button keypress from the emulator


@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {

if (keyCode == KeyEvent.KEYCODE_BACK) {
Intent intent1 = new Intent(this, MainActivity.class);
startActivity(intent1);
finish();
}
return super.onKeyDown(keyCode, event);
}

Thursday 20 September 2012

android: Listview -set visibility of checkboxes in all the listitems


ListView list=getListView();
int count = list.getChildCount();
for (int i = 0; i < count; i++) {
   View child = list.getChildAt(i);
   CheckBox cb11=(CheckBox)child.findViewById(R.id.checkBox1);
  cb11.setVisibility(View.VISIBLE);
}

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>