gpt4 book ai didi

java - 安卓 : Hide the soft keyboard when click the EditView

转载 作者:行者123 更新时间:2023-11-29 06:42:02 24 4
gpt4 key购买 nike

在我的应用程序中,我必须从用户那里获取日期。
首先,我使用一个按钮,当用户单击该按钮时,将出现一个对话框,其中包含日期选择器并在一个 TextView 中获取结果。
现在我想用 EditView 替换按钮。单击 EditView 时,必须出现对话框,并且不应出现键盘。

@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;
}

所以请任何人帮助我?

最佳答案

我做的完全一样,我正在发布一些代码试试看。它应该工作..

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;
}
});

在您的 xml 文件中为 edittext 声明这些属性。

android:clickable="true"
android:cursorVisible="false"
android:editable="false"
android:inputType="none"
android:singleLine="true"

希望它能奏效。

关于java - 安卓 : Hide the soft keyboard when click the EditView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10442470/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com