postheadericon Android Character Picker Dialog Example



An Example of Character Picker Dialog in Android.




File Name : MainActivity.java


package com.bipinrupadiya.charachterpickerdemo;

import android.app.Activity;
import android.os.Bundle;
import android.text.method.CharacterPickerDialog;
import android.view.View;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class MainActivity extends Activity {

private CharacterPickerDialog CPD = null;
String chrOptions = "0123456789";

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final EditText t = (EditText) findViewById(R.id.editText1);
Button button = (Button) this.findViewById(R.id.button1);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
CPD.setTitle("Select Charecter");
CPD.show();

}
});

CPD = new CharacterPickerDialog(this, new View(this), null, chrOptions,
true) {
public void onClick(View v) {

String c = "";
c = ((Button) v).getText().toString();
Toast.makeText(getApplicationContext(), "" + c,
Toast.LENGTH_SHORT).show();

t.setText(t.getText().toString() + c);
dismiss();
}

};
}
}

File Name : 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"
    tools:context=".MainActivity" >

    <Button
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="142dp"
        android:text="Button" />

    <EditText
        android:id="@+id/editText1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentRight="true"
        android:layout_alignParentTop="true"
        android:layout_marginTop="55dp"
        android:ems="10" >

        <requestFocus />
    </EditText>

</RelativeLayout>




2 comments:

JeCsOn said...

hmmmmm

IT said...

Great Article
android based projects

Java Training in Chennai

FInal Year Project Centers in Chennai

Java Training in Chennai

projects for cse

The Angular Training covers a wide range of topics including Components, Angular Directives, Angular Services, Pipes, security fundamentals, Routing, and Angular programmability. The new Angular TRaining will lay the foundation you need to specialise in Single Page Application developer. Angular Training

Follow by Email

Total Pageviews

© BipinRupadiya.com. Powered by Blogger.