如何设置监听器?

时间:2013-04-05 04:22:37

标签: text input dialog

我想我需要一个听众,但不能设置它。 在下面的代码中,时间对话框和日期对话框都有效。滚动的小对话框出现,我选择日期/时间,然后选择,我有我的约会。但我不能让文本输入工作。   我从一个示例程序中尝试了几次这段代码的迭代,该程序具有:         bnBodyEntered = true;         bodyDialog = new TextInputDialog(this);         bodyDialog.setText( “身”); 这段代码显示了带有字母滚轮的文本对话框,但程序已经过了它,当我输入几个字母并且没有选择任何事情。这使得因为我没有建立一个听众。所以我补充说(如上所述)     bodyDialog.setOnDismissListener(textSetListener); 使用几个“setOn ---- Listener”值并且它仍然运行过去,或者我得到各种编译错误。

这是我的WIMMOne手表,因此版本7并没有虚拟键盘。它需要是一个对话框。

(注意:我在发布之前删除了评论代码的大部分内容 - 可能还有更多内容,所以如果它自那以后就没有了 - 抱歉。)

谢谢,Clark

/******************************
 * Wimm imports
 ******************************/
import com.wimm.framework.app.Dialog;
import com.wimm.framework.app.DatePickerDialog;
import com.wimm.framework.app.DatePickerDialog.OnDateSelectedListener;
import com.wimm.framework.app.LauncherActivity;
import com.wimm.framework.app.TextInputDialog;
import com.wimm.framework.app.TimePickerDialog;
import com.wimm.framework.app.TimePickerDialog.OnTimeSelectedListener;



@ Override
public void onCreate(Bundle savedInstanceState)
   {
    super.onCreate(savedInstanceState);
    Log.d("RemindEA","01S onCrt");
    setContentView(R.layout.reminder_edit_activity);

            . . . 
            . . . 


    mBodyText  = (EditText)findViewById(R.id.body);
    mTimeButton = (Button)findViewById(R.id.reminder_time);
    mDateButton = (Button)findViewById(R.id.reminder_date);

    mConfirmButton = (Button)findViewById(R.id.confirm);
    Log.d("RemindEA","10S onCrtV df");


    //-------------  TEXT INPUT
    mBodyText.setOnClickListener( new View.OnClickListener() 
               {
        public void onClick(View v)
        {
         Log.d("RemindEA","21> onClkV:Body");
                     showDialog(BODY_DIALOG_ID);
                 Log.d("RemindEA","22< onClkV:Body:" + strBody);

         mBodyText.setText(bodyDialog.getText());
            return;
         }
               } );

    //--------------------------  TIME INPUT
    mTimeButton.setOnClickListener( new View.OnClickListener()     
           {
        @Override
        public void onClick(View v)
           {
        Log.d("RemindEA","25> onClkV:Time");
        showDialog(TIME_DIALOG_ID);
        Log.d("RemindEA","26< onClkV:Time");
           }
               } );


    //--------------------------  DATE INPUT
    mDateButton.setOnClickListener( new View.OnClickListener()
       {
        @Override
        public void onClick(View v)
           {
        Log.d("RemindEA","30> onClkV:Time");
        showDialog(DATE_DIALOG_ID);
        Log.d("RemindEA","31< onClkV:Time");
           }
           }  );

    protected Dialog onCreateDialog(int id) 
     {
  Log.d("RemindEA","70S Dialog:" + id);
  switch (id) 
     {
      // if we want a time dialog--------------
      case TIME_DIALOG_ID:
         Log.d("RemindEA","71S TIME_DIALOG_ID");
     timeDialog = new TimePickerDialog(this);
     timeDialog.setTimeSelectedListener(timeSetListener);
             timeDialog.setTime(mCalendar.get(Calendar.HOUR_OF_DAY),
                                 mCalendar.get(Calendar.MINUTE));
     Log.d("RemindEA","73S TIME_D:" + timeDialog);
     return timeDialog;

    // if we want a date dialog ---------------
    case DATE_DIALOG_ID:
       Log.d("RemindEA","75S DATE_DIALOG_ID-26");
       mCalendar = Calendar.getInstance();
       Log.d("RemindEA","76S DATE_DIALOG_ID-27");
       dateDialog = new DatePickerDialog(this);
       dateDialog.setDateSelectedListener(dateSetListener);
       dateDialog.setDate(mCalendar.get(Calendar.DAY_OF_MONTH),
               mCalendar.get(Calendar.MONTH   ));
       Log.d("RemindEA","77S DATE_D:" + dateDialog);
       return dateDialog;

    // if we want text input dialog ---------------------
    case BODY_DIALOG_ID:
       Log.d("RemindEA","80S BODY_DIALOG_ID");
       bnBodyEntered = true;
       Log.d("RemindEA","81S TITLE");
       bodyDialog = new TextInputDialog(this);
          //---> ADDED LINE BELOW TO CREATE A LISTENER: GET ERROR <-----
          // ERROR BELOW: setOnDismissListener cannot be resolved to a type
               bodyDialog.setOnDismissListener(textSetListener);
          //------------------------------------------
                //ALSO //.setOnKeyListener(onKeyListener) - others     
           Log.d("RemindEA","82S New");
       bodyDialog.setText("body");
       Log.d("RemindEA","83X:" + bodyDialog);
       return bodyDialog;   
      }
      return null;
    } 

    private OnTimeSelectedListener timeSetListener = new OnTimeSelectedListener() 
       {
        public void onTimeSelected(int arg0, int arg1) 
       {
    Log.d("RemindEA","90S onTimeSelected");
    intHH = arg0;
    intMN = arg1;
    Log.d("RemindEA","91S schedule:" + intHH + ":" +  intMN);
    //updateDisplay();
       }
       };


    private OnDateSelectedListener dateSetListener = new OnDateSelectedListener() 
       {
        public void onDateSelected(int arg0, int arg1) 
           {
    Log.d("RemindEA","92S onTimeSelected");
    intDD = arg0;
    intMM = arg1;
    Log.d("RemindEA","93S schedule:" + intDD + ":" +  intMM);
    //updateDisplay();
       }
         };

 //------------------------------------
 //  -----> ERROR: setOnDismissListener cannot be resolved to a type
    private setOnDismissListener textSetListener = new setOnDismissListener 
 //------------------------------------
       {
        private void textSetListener()  // bodySetListener ()
           {
        Log.d("RemindEA","100S BodyLisner");  //<- does not get here on <done>
        return;
           }
        };

1 个答案:

答案 0 :(得分:1)

经过数小时的猜测和错误,这很有效。

我不认为“Return bodyDialog”会做任何事情;我最终直接从侦听器更新了EditText字段。 “arg0”有一个很长的对话名称 - 没有用。但是你有它可以防止编译错误。

这可能是WIMMOne独有的,它没有虚拟键盘,你需要使用它们的文本输入对话框。

protected Dialog onCreateDialog(int id) 
   {
switch (id)
       . . . .  
       case BODY_DIALOG_ID:
          bodyDialog = new TextInputDialog(this);
          bodyDialog.setOnDismissListener(textSetListener);
          return bodyDialog;


private OnDismissListener textSetListener = new OnDismissListener() 
 {
@Override
public void onDismiss(DialogInterface arg0)
   {
     Log.d("RemindEA","101S BodyLisner" + arg0);
     String strxx = bodyDialog.getText();
     mBodyText.setText(strxx);

   }
 };