0

我使用 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。请任何人帮助我....

4

2 回答 2

2
    final InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
    imm.hideSoftInputFromWindow(yourEditText.getWindowToken(), 0);

您始终可以禁用您的编辑文本,只需将可单击、已启用、可聚焦属性设置为 false。

于 2012-10-24T10:57:05.930 回答
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();
                    }
                });
于 2012-10-24T11:33:43.977 回答