0

The problem I'm having is capturing data from my option menu dialogs. The example below has an options menu with four dialog layout to of the dialog capture a stringa that I need returned to the host activity. Can someone explain why the code below does not work. Here is a sample of my code:

class ClientConfigActivity extends Activity with TypedActivity {

// Called when the activity is first created                        
override def onCreate(savedInstanceState: Bundle) {                 
  super.onCreate(savedInstanceState)                                
  setContentView(R.layout.clientconfig)                             

  // Dialog Test                                                    
  Log.d("Option", getIntent.getExtras.get("localIP").toString)      
  Log.d("Option", getIntent.getExtras.get("remoteIP").toString)     
}                                                                   

// Relieves results from clientConfig option menu                                     
override def onActivityResult(requestCode: Int, resultCode: Int, data: Intent) {      
  super.onActivityResult(requestCode, resultCode, data)                             

  requestCode match {                                                                 
    case 0 => Log.d("Option", "Option 1 got here")                                    

      //local_IPAddress.setText("hello")                                              

    case 1 => Log.d("Option", "Option 2 got here")                                    
  }                                                                                   
}         

// Called when an options menu is created.               
override def onCreateOptionsMenu(menu: Menu) = {         
  // Inflates XML file into something that can be used.  
  val inflater = getMenuInflater                         
  inflater.inflate(R.menu.clientconfigmenu, menu)        

  super.onCreateOptionsMenu(menu)                        
}      

// Test to see which option was clicked.                                                                                           
override def onOptionsItemSelected(item: MenuItem) = {                                                                             
  // Check for clientLocation_option                                                                                               
  item.getItemId match {                                                                                                           

    case R.id.option_LocalConfig => {                                                                                              
      // Set reference to dialog_localconfig_layout.xml                                                                            
      val dialog = new Dialog(this)                                                                                                
      dialog.requestWindowFeature(Window.FEATURE_LEFT_ICON)                                                                        
      dialog.setContentView(R.layout.dialog_localconfig_layout)                                                                    
      dialog.setTitle("Local Configuration")                                                                                       

      // dialog_remoteconfig_layout.xml References                                                                                 
      val local_IP = dialog.findViewById(R.id.setLocalIPaddress).asInstanceOf[EditText]                                            
      val local_PortNumber = dialog.findViewById(R.id.setLocalPortNum).asInstanceOf[EditText]                                      
      val local_Done_Button = dialog.findViewById(R.id.local_DoneButton).asInstanceOf[Button]                                      

      // RemoteConfig Done Button Listener                                                                                         
      dialog.show()                                                                                                                
      dialog.setFeatureDrawableResource(Window.FEATURE_LEFT_ICON, android.R.drawable.ic_menu_myplaces)                             

      // LocalConfig Done Button Listener                                                                                          
      local_Done_Button.setOnClickListener(new OnClickListener {                                                                   
        override def onClick(view: View) {                                                                                         
          // Start the ClientConfig Activity w/explicit intent                                                                     
          val intent = new Intent(dialog.getContext, classOf[ClientConfigActivity])                                                
          intent.putExtra("localIP", local_IP.getText.toString)                                                                    
          intent.putExtra("localPort", local_PortNumber.getText.toString)                                                          
          startActivityForResult(intent, 0)                                                                                        
        }                                                                                                                          
      })                                                                                                                           
    }                                                                                                                              

    case R.id.option_RemoteConfig => {                                                                                             
      // Set reference to dialog_remoteconfig_layout.xml                                                                           
      val dialog = new Dialog(this)                                                                                                
      dialog.requestWindowFeature(Window.FEATURE_LEFT_ICON)                                                                        
      dialog.setContentView(R.layout.dialog_remoteconfig_layout)                                                                   
      dialog.setTitle("Remote Configuration")                                                                                      

      // dialog_remoteconfig_layout.xml References                                                                                 
      val remote_IP = dialog.findViewById(R.id.setRemoteIP).asInstanceOf[EditText]                                                 
      val remote_PortNumber = dialog.findViewById(R.id.setRemotePortNum).asInstanceOf[EditText]                                    
      val remote_Done_Button = dialog.findViewById(R.id.remote_DoneButton).asInstanceOf[Button]                                    

      //Show dialog_remoteconfig_layout Custom Layout                                                                              
      dialog.show()                                                                                                                
      dialog.setFeatureDrawableResource(Window.FEATURE_LEFT_ICON, android.R.drawable.ic_menu_call)                                 

      // RemoteConfig Done Button Listener                                                                                         
      remote_Done_Button.setOnClickListener(new OnClickListener {                                                                  
        override def onClick(view: View) {                                                                                         
          // Start the ClientConfig Activity w/explicit intent                                                                     
          val intent = new Intent(dialog.getContext, classOf[ClientConfigActivity])                                                
          intent.putExtra("remoteIP", remote_IP.getText.toString)                                                                  
          intent.putExtra("remotePortNum", remote_PortNumber.getText.toString)                                                     
          startActivityForResult(intent, 1)                                                                                        
        }                                                                                                                          
      })                                                                                                                           
    }                                                                                                                              

  }                                                                                                                                

  super.onOptionsItemSelected(item)                                                                                                
}                                                                                                                                                                                                                                                                
Jonathan Hall
  • 75,165
  • 16
  • 143
  • 189
Ray Goodwin
  • 183
  • 1
  • 3
  • 9

1 Answers1

0

What happens when you try to show the dialog?

Dialogs have a life-cycle that may seem a little strange. See http://developer.android.com/guide/topics/ui/dialogs.html for details.

You're expected to call showDialog(yourDialogId) to open the dialog. Dialog creation is done in onCreateDialog(id). Here you'll match the id to your yourDialogId and create and return the dialog.

thoredge
  • 12,237
  • 1
  • 40
  • 55