Imran's Blog- Android Imran's Blog- Android Imran's Blog- Android Imran's Blog- Android

Tuesday, July 3, 2012

Android : CharacterPickerDialog Example



main.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" >

        <Button
        android:id="@+id/Button01"
        android:layout_gravity="center"
        android:layout_marginTop="40dp"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="CharacterPickerDialog" />

</LinearLayout>




CharacterPickerDialogActivity.java:
public class CharacterPickerDialogActivity extends Activity {
    /** Called when the activity is first created. */
 private CharacterPickerDialog cpd = null;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        Button button = (Button) this.findViewById(R.id.Button01);
        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                cpd.show();
            }
        });
          String options="0123456789ABCDEF";  
          cpd= new CharacterPickerDialog(this, new View(this), null,options,false){ 
           public void onClick(View v) {
                     
                     Toast.makeText(getApplicationContext(),
                             "onClick! " + ((Button) v).getText().toString(),
                             Toast.LENGTH_SHORT).show();
                     dismiss();
            }
           public void onItemClick(AdapterView parent, View view, int position, long id)
                 {
                     
                     String message = ("onItemClick! " + ((Button) view).getText().toString())
                             + " position=" +
                             position
                             + " id=" + id;
                     Toast.makeText(getApplicationContext(), message, Toast.LENGTH_SHORT).show();
                     dismiss();
                 }
      };
    }
}


Download Source Code: CharacterPickerDialogExample








 
Powered by Blogger