安卓:隐藏软键盘,当点击EditView中 [英] Android : Hide the soft keyboard when click the EditView
本文介绍了安卓:隐藏软键盘,当点击EditView中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在我的申请,我必须从用户那里得到的日期。
首先,我用一个按钮,当用户点击该按钮会出现一个对话框,其中包含日期选择器和一个TextView中得到的结果。
现在我想通过EditView中被替换的按钮。在点击EditView中的对话框,将出现无键盘应该会出现。
In my application , I have to get date from the user.
First I use one button, when the user clicks the button a dialog box will appear which holds datepicker and get the result in one TextView.
Now I want to replace the button by EditView. On Clicking the EditView the dialog box will have to appear and no keyboards should appear.
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.report);
EmployeeGlobal eg=(EmployeeGlobal)getApplicationContext();
String uid=eg.getMainUserId();
ArrayList<String>list=eg.getAllProjects(uid);
Spinner spinner = (Spinner)findViewById(R.id.all_projs);
ArrayAdapter<String> spinnerArrayAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, list);
spinnerArrayAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner.setAdapter(spinnerArrayAdapter);
Toast.makeText(getApplicationContext(), "Report"+uid, Toast.LENGTH_LONG).show();
mStartDateDisplay=(TextView)findViewById(R.id.strdate);
mEndDateDisplay = (TextView) findViewById(R.id.enddate);
mEndDate = (Button) findViewById(R.id.end_dateb);
mStartDate=(Button)findViewById(R.id.start_dateb);
mYear=c1.get(Calendar.YEAR);
mMonth = c1.get(Calendar.MONTH);
mDay = c1.get(Calendar.DAY_OF_MONTH);
mStartDate.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
showDialog(DATE_DIALOG_START);
//updateDisplay(mStartDateDisplay);
}
});
mEndDate.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
showDialog(DATE_DIALOG_END);
//updateDisplay(mEndDateDisplay);
}
});
}
private void updateDisplay(TextView T) {
T.setText(
new StringBuilder()
// Month is 0 based so add 1
.append(mMonth + 1).append("-")
.append(mDay).append("-")
.append(mYear).append(" "));
}
private DatePickerDialog.OnDateSetListener mFromDateSetListener =
new DatePickerDialog.OnDateSetListener() {
public void onDateSet(DatePicker view, int year,
int monthOfYear, int dayOfMonth) {
mYear = year;
mMonth = monthOfYear;
mDay = dayOfMonth;
updateDisplay(mStartDateDisplay);
}
};
private DatePickerDialog.OnDateSetListener mToDateSetListener =
new DatePickerDialog.OnDateSetListener() {
public void onDateSet(DatePicker view, int year,
int monthOfYear, int dayOfMonth) {
mYear = year;
mMonth = monthOfYear;
mDay = dayOfMonth;
updateDisplay(mEndDateDisplay);
}
};
@Override
protected Dialog onCreateDialog(int id) {
switch (id) {
case DATE_DIALOG_END:
return new DatePickerDialog(this,mToDateSetListener, mYear, mMonth, mDay);
case DATE_DIALOG_START:
return new DatePickerDialog(this,mFromDateSetListener,mYear, mMonth, mDay);
}
return null;
}
所以,请谁能帮助我?
So please anyone help me?
推荐答案
我已经做了完全一样的我张贴一些code尝试。它应该工作。
I have done exactly same i am posting some code try it. It should work..
EditText time_text_1;
time_text_1.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_UP) {
//CREATE YOUR DATE PICKER DIALOG HERE.
}
return false;
}
});
在您的EditText xml文件
声明这些属性。
declare these properties in your xml file for edittext.
android:clickable="true"
android:cursorVisible="false"
android:editable="false"
android:inputType="none"
android:singleLine="true"
希望它会工作。
这篇关于安卓:隐藏软键盘,当点击EditView中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文