0

我想創建自定義提醒對話框,兩個字段之一是編輯文本和其他是微調。問題是我只能看到微調,我無法看到編輯文本。編輯文本可用,但微調控件隱藏了編輯文本的內容。所以我的問題是我如何設置編輯文本和微調的位​​置。在android中的自定義提醒對話框覆蓋其他對象

以下是我的代碼。

AlertDialog.Builder alertDialog = new AlertDialog.Builder(
      RecordAudio.this); 
    alertDialog.setTitle("Would you Like to save your Recording"); 
    alertDialog.setMessage("Enter Audio Name"); 
    alertDialog.setIcon(R.drawable.save_icon); 

    final EditText editTextAudioName = new EditText(RecordAudio.this); 
    RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(
      RelativeLayout.LayoutParams.WRAP_CONTENT, 
      RelativeLayout.LayoutParams.WRAP_CONTENT); 
    editTextAudioName.setLayoutParams(lp); 
    alertDialog.setView(editTextAudioName); 

    final Spinner spinnerListData = new Spinner(RecordAudio.this); 
    RelativeLayout.LayoutParams lpSpinner = new RelativeLayout.LayoutParams(
      RelativeLayout.LayoutParams.WRAP_CONTENT, 
      RelativeLayout.LayoutParams.WRAP_CONTENT); 
    spinnerListData.setLayoutParams(lpSpinner); 
    alertDialog.setView(spinnerListData); 

    dataManipulatorClass = new DataManipulatorClass(this); 
    names2 = dataManipulatorClass.selectAll(); 

    stg1 = new String[names2.size()]; 
    int x = 0; 
    String stg; 

    for (String[] name : names2) { 
     stg = "Class Name : " + name[1]; 
     stg1[x] = stg; 
     x++; 
    } 

    ArrayAdapter<String> adapter = new ArrayAdapter<String>(
      RecordAudio.this, android.R.layout.simple_spinner_item, stg1); 
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); 
    spinnerListData.setAdapter(adapter); 
    spinnerListData.setWillNotDraw(false); 

    spinnerListData.setOnItemSelectedListener(new OnItemSelectedListener() { 
     @Override 
     public void onItemSelected(AdapterView<?> parent, View v, 
       int position, long id) { 
      Toast.makeText(getApplicationContext(), 
        "Spinner Item selected", Toast.LENGTH_LONG).show(); 
     } 

     @Override 
     public void onNothingSelected(AdapterView<?> arg0) { 
      // TODO Auto-generated method stub 
     } 
    }); 

    alertDialog.setPositiveButton("Save", 
      new DialogInterface.OnClickListener() { 
       public void onClick(DialogInterface dialog, int which) { 

        Code.audioName = editTextAudioName.getText().toString() 
          .trim(); 

        recorder = new MediaRecorder(); 
        recorder.setAudioSource(MediaRecorder.AudioSource.MIC); 
        recorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4); 
        recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB); 
        recorder.setOutputFile(getFilename()); 
        recorder.setOnErrorListener(errorListener); 
        recorder.setOnInfoListener(infoListener); 

        try { 
         recorder.prepare(); 
         recorder.start(); 

         if (Code.i == true) { 
          new Timer().schedule(new TimerTask() { 
           @Override 
           public void run() { 
            runOnUiThread(new Runnable() { 
             @Override 
             public void run() { 
              stopRecording(); 
              enableButtons(false); 
             } 
            }); 
           } 
          }, 41000); 
         } else { 
          new Timer().schedule(new TimerTask() { 
           @Override 
           public void run() { 
            runOnUiThread(new Runnable() { 
             @Override 
             public void run() { 
              stopRecording(); 
              enableButtons(false); 
             } 
            }); 
           } 
          }, 21000); 
         } 
        } catch (IllegalStateException e) { 
         e.printStackTrace(); 
        } catch (IOException e) { 
         e.printStackTrace(); 
        } 
        myChronometer.setBase(SystemClock.elapsedRealtime()); 
        myChronometer.start(); 
       } 
      }); 

    alertDialog.setNegativeButton("Cancel", 
      new DialogInterface.OnClickListener() { 
       public void onClick(DialogInterface dialog, int which) { 
        dialog.cancel(); 
        enableButtons(false); 
       } 
      }); 
    alertDialog.show(); 
+0

你能證明它是如何現在看起來? – coder

+0

@coder,http://i.share.pho.to/89125a67_o.png。 – InnocentKiller

+0

@coder,我無法看到我的編輯文本。 – InnocentKiller

回答

1

的setView方法: -

設置自定義視圖成爲對話框的內容。如果提供的 視圖是ListView的實例,則將使用淺色背景。

,所以你需要在一些佈局,例如增加的LinearLayout既視圖,然後呼籲

1

這是因爲你設置的意見,以提醒對話框兩次的setView方法。 首先定義一個Linearlayout,然後將您的視圖(編輯文本和微調)添加到它,然後將該Linearlayout設置爲警報對話框。

的LinearLayout parentLayout =新的LinearLayout( RecordAudio.this);

LinearLayout.LayoutParams linearParams =新 LinearLayout.LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); (EditAudio.this);

final EditText editTextAudioName = new EditText(RecordAudio.this);

RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(
     RelativeLayout.LayoutParams.WRAP_CONTENT, 
     RelativeLayout.LayoutParams.WRAP_CONTENT); 
editTextAudioName.setLayoutParams(lp); 
parentLayout.addView(editTextAudioName); 

final Spinner spinnerListData = new Spinner(RecordAudio.this); 
RelativeLayout.LayoutParams lpSpinner = new RelativeLayout.LayoutParams(
     RelativeLayout.LayoutParams.WRAP_CONTENT, 
     RelativeLayout.LayoutParams.WRAP_CONTENT); 
spinnerListData.setLayoutParams(lpSpinner); 
parentLayout.addView(spinnerListData);