3

我一直在寻找characterpickerdialog用法的示例,但没有找到。你介意张贴吗?

4

1 回答 1

2

CharacterPickerDialog 示例:

示例 1:

public class CharacterPickerDialogTest extends Activity {  

    private RelativeLayout mainView = null;  
    private TextView tv = null;  
    private Button button = null;  
    private CharacterPickerDialog cpd = null;  

    public void onCreate(Bundle savedInstanceState) {  
        super.onCreate(savedInstanceState);  
        mainView = new RelativeLayout(this);  
        tv = new TextView(this);  
        RelativeLayout.LayoutParams lp_tv = new RelativeLayout.LayoutParams(-2,-2);  
        lp_tv.addRule(RelativeLayout.CENTER_IN_PARENT);  
        tv.setLayoutParams(lp_tv);  
        tv.setGravity(Gravity.CENTER_HORIZONTAL);  
        tv.setText(" shown here result");  
        button = new Button(this);  
        RelativeLayout.LayoutParams lp_button = new RelativeLayout.LayoutParams(-2, -2);  
        lp_button.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);  
        lp_button.addRule(RelativeLayout.CENTER_HORIZONTAL);  
        button.setLayoutParams(lp_button);  
        button.setText("open");  
        button.setOnClickListener(new OnClickListener() {  
            public void onClick(View v) {  
                if (cpd == null) {  
                    cpd_init();  
                }  
                cpd.show();  
            }  
        });  
        mainView.addView(tv);  
        mainView.addView(button);  
        setContentView(mainView);  
    }  

   // Cpd initialization
    void cpd_init() {  
        EditText et=new EditText(this);  
        et.setLayoutParams(new LinearLayout.LayoutParams(-1,-2));  
        final String options="0123456789ABCDEF";  
        cpd= new CharacterPickerDialog(this, new View(this), null,options,false){  
            public void onClick (View v){  
                //tv.setText("????"+((Button)v).getText().toString());   
                dismiss();   
            }  
            public void onItemClick (AdapterView parent, View view, int position, long id){  
                tv.setText("You pressed Button"+((Button)view).getText().toString()+"\n");   
                tv.append("the Button's position is"+position+"\n");  
                tv.append("the buton ID"+id);  
                dismiss();   
            }  
        };  

    }  
}  

示例 2:在按钮单击时轻松显示:

public  class CharacterPickerDialogDialogActivity extends Activity {
     Private CharacterPickerDialog CPD = null ;

    / ** Called when the Activity is Created first. * / 
    @ 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 (View v) {onClick
                 onClick does the processing of the Cancel button / /
                Toast.makeText (getApplicationContext (),
                        "OnClick!" + ((Button) v). getText (). toString (),
                        Toast.LENGTH_SHORT).show();
                dismiss();
            }

            public  void OnItemClick(AdapterView parent, View View, int position, long id)
            {
                / / OnItemClick does the processing of character button 
                String message = ( "OnItemClick!" + ((Button) View). getText(). toString())
                        + "position =" +
                        position
                        + "id =" + id;
                Toast.makeText (getApplicationContext(), message, Toast.LENGTH_SHORT).show();
                dismiss();
            }
        ;}
    }
}
于 2012-07-03T09:44:49.050 回答