我使用alertdialog使用编辑文本显示我的txt文件内容。这是用于警告对话框的代码
File sdcard = Environment.getExternalStorageDirectory();
file = new File(sdcard.getPath() + Constants.USERNOTE_FOLDER + "/"+value);
System.out.println("txt file path name : "+file);
//Read text from file
StringBuilder text = new StringBuilder();
try {
BufferedReader br = new BufferedReader(new FileReader(file));
String line;
while ((line = br.readLine()) != null) {
text.append(line);
text.append('\n');
}
}
catch (IOException e) {
//You'll need to add proper error handling here
}
System.out.println("text value : "+text);
String filename=null;
String toRemove = ".txt";
if(value.endsWith(toRemove)) {
filename=value.substring(0,value.length()-toRemove.length());
}
System.out.println("file name : "+filename);
LayoutInflater factory = LayoutInflater.from(ViewUserNote.this);
final View textEntryView = factory.inflate(R.layout.readusernote, null);
EditText readval = (EditText)textEntryView.findViewById(R.id.readtext);
readval.setText(text);
Builder alert = new Builder(ViewUserNote.this);
AlertDialog dialog =alert.create();
dialog.setTitle(filename);
dialog.setView(textEntryView);
dialog.show();
在此单击编辑文本时,键盘不应显示。我该如何实施tis。请任何人帮助我......
答案 0 :(得分:2)
final InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(yourEditText.getWindowToken(), 0);
您可以随时禁用edittext,只需将setClickable,enabled,focusable属性设置为false。
答案 1 :(得分:1)
修改强>
alert.setNegativeButton(cancel,
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
saveimage();
InputMethodManager im = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
im.hideSoftInputFromWindow(input.getWindowToken(), 0);
dialog.cancel();
}
});