0

I have editbox I want when click on it to show TimePickerDialog instead of the keyboard , and when select the time the picker disappear and the time be shown in the edittext

这个 EditText 是这样的适配器类

public class TminuseistAdaptar  extends ArrayAdapter<Tr> {

    private final Context context;
    ArrayList<Tr> TrBasics ; 

    static final int TIME_DIALOG_ID = 0;

    CheckBox Confirm ; 
    ImageButton DialUp;

     EditText data ; 

    public TminuseistAdaptar(Context context, int  ResourceId,
            ArrayList<Tr> items)
    {


        super(context, ResourceId, items);
         this.context = context;
         this.TrBasics = items ; 

    }

    public View getView(int position, View convertView, ViewGroup parent) {

}
}

我为editText做了类似的事情

textViewEncounterType = (EditText) rowView.findViewById(R.id.TminuseTime);
        textViewEncounterType.setText(TreatementMinuseObject.TBasic.TreatementTime);
        textViewEncounterType.setTag(position);



        textViewEncounterType.setClickable(true);
        textViewEncounterType.setInputType(InputType.TYPE_NULL);

        textViewEncounterType.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {

                new TimePickerDialog(context, mTimeSetListener, hour, minute, false);

            }
        });

但什么也没有出现,我在另一个类中调用这个适配器类扩展片段

public class TminusList   extends Fragment {

此致

4

2 回答 2

4

您可以执行以下操作(对于片段实现):

startTxt = (EditText) v.findViewById(R.id.joindate);
startTxt.setClickable(true);
startTxt.setInputType(InputType.TYPE_NULL);

startTxt.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
        DialogFragment newFragment = new TimeDialog();
        newFragment.show(getFragmentManager(), "dialog");
    }
});

和时间对话:

public class TimeDialog extends DialogFragment {

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
        // Set your view
    }

    @Override
    public Dialog onCreateDialog(Bundle savedInstanceState) {
        return new TimePickerDialog(getActivity(), this, hour, minute, false);      }
}

此代码将导致 EditText 框弹出时间选择器对话框而不是键盘(一旦您输入时间选择器对话框代码)。

请注意,您需要在 XML 中设置 EditText(在上面的示例中,它将是带有joindateid 的 EditText),android:focusableInTouchMode="false"否则需要单击两次才能打开对话框。

于 2012-07-08T14:18:01.770 回答
2

尝试

startTxt.setOnTouchListener(new OnTouchListener() {

            @Override
            public boolean onTouch(View arg0, MotionEvent arg1) {
                // TODO Auto-generated method stub
                //show DateTimepicker
                return true; //very important in your case if you return false keayboard will open
            }
        });
于 2012-07-08T14:21:48.397 回答