我试着看看这里关于日期选择器出现EditText的其他问题,但我在让它工作时遇到了问题。
我看过一些例子,你可以使用setOnClickListenersetOnTouchListener,哪一个是最好的?
我也看到过一些不同的设计,如何改变设计?
下面是目前为止我的代码,尝试使用其他示例中的代码,但未能成功。

import android.app.Activity;
import android.os.Bundle;
import android.widget.EditText;
import android.widget.TextView;


/**
 * Created by MOS182 on 7/21/13.
 */
public class AddReminder extends Activity {

    TextView Title, Amount, PaymentDate, ReminderDate, ReminderTime;
    EditText eTitle, eAmount, ePaymentDate, eReminderDate, eReminderTime;

    @Override
    protected void onCreate(Bundle savedInstanceState)
    {


        super.onCreate(savedInstanceState);
        setContentView(R.layout.reminders_dialog);
        initializeVariables();
    }



    private void initializeVariables()
    {
        Title = (TextView) findViewById(R.id.tvTitle);
        Amount = (TextView) findViewById(R.id.tvAmount);
        PaymentDate = (TextView) findViewById(R.id.tvPaymentDate);
        ReminderDate = (TextView) findViewById(R.id.tvReminderDate);
        ReminderTime = (TextView) findViewById(R.id.tvReminderTime);
        eTitle = (EditText) findViewById(R.id.etTitle);
        eAmount = (EditText) findViewById(R.id.etAmount);
        ePaymentDate = (EditText) findViewById(R.id.etPaymentDate);
        eReminderDate = (EditText) findViewById(R.id.etReminderDate);
        eReminderTime = (EditText) findViewById(R.id.etReminderTime);
    }


}

最佳答案

我使用了setonclicklistenerEditText方法来显示一个DatePicker
然后在XML文件中设置EditText属性android:focusable="false",这样就可以避免焦点和虚拟键盘。

yourEditText.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            //To show current date in the datepicker
            Calendar mcurrentDate=Calendar.getInstance();
            mYear=mcurrentDate.get(Calendar.YEAR);
            mMonth=mcurrentDate.get(Calendar.MONTH);
            mDay=mcurrentDate.get(Calendar.DAY_OF_MONTH);

            DatePickerDialog mDatePicker=new DatePickerDialog(**YourActivityName**.this, new OnDateSetListener() {
                public void onDateSet(DatePicker datepicker, int selectedyear, int selectedmonth, int selectedday) {
                    // TODO Auto-generated method stub
                    /*      Your code   to get date and time    */
                }
            },mYear, mMonth, mDay);
            mDatePicker.setTitle("Select date");
            mDatePicker.show();  }
    });

试试这个…评论你的想法…谢谢…

09-27 05:44