20 Feb 2013

CharacterPickerDialog in Android.

You can create custom character Picker, same way we can make custom keyboard using this concept. 


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.Toast;

public class CharacterPickerDialogActivity extends Activity
{    
      private CharacterPickerDialog cpd = null;
      String options="0123456789ABCDEFGHIJ";
     
      @Override
      public void onCreate(Bundle savedInstanceState)
      {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);

            Button button = (Button) this.findViewById(R.id.Button01);
            button.setOnClickListener(new View.OnClickListener()
            {
                  @Override
                  public void onClick(View v)
                  {
                        cpd.show();
                  }
            });          
            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();
                  }
            };
      }
}

i will be happy if you will provide your feedback or follow this blog. Any suggesion and help will be appreciated.
Thank you :)

2 comments: