本文介绍了[机器人]如何从意图的结果,从preference屏幕推出?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的意图,从推出歌厅返回结果需要帮助preference屏幕

I need help in geting results back from intent launched from preference screen

   // Intent preference 
   DevicePref = 
   getPreferenceManager().createPreferenceScreen(this); 

   // Show a Screen with list of Devices Discovered 
   Intent i = new Intent(this,getDevice.class); 
   DevicePref.setIntent(i); 
   DevicePref.setTitle("Select Device"); 
   DevicePref.setSummary(mSelectedDevice); 
   deviceOptionsCat.addPreference(DevicePref); 

我希望用户选择设备...在preference screeen我秀选择设备。当用户点击,另一个屏幕是由意向推出其中,所有的设备都被列出。用户选择该设备。

I want user to select device... In preference screeen I show "Select Device" .. when user clicks that, another screen is launched by intent where all devices are listed. User selects the device.

现在我怎么知道用户选择哪些设备?我想更新在摘要。

Now how do I know user selected which device? And I want to update that in the summary.

PLS。让我知道谢谢

Pls. let me know Thanks

推荐答案

我得到了答案,希望它会帮助我这样的人......

I got the answer, Hope it will help someone like me...

不要再提意图,同时创造preference像我一样在上面code ..提到打算在preferenceClickListener然后做StartActivityForResult()

Do not mention intent while creating preference like I did in above code.. Mention intent on OnPreferenceClickListener and then do StartActivityForResult()

    // Intent preference 
   DevicePref = getPreferenceManager().createPreferenceScreen(this); 
   // Show a Screen with list of Devices Discovered 

   DevicePref.setOnPreferenceClickListener(onPreferenceClick);

   DevicePref.setTitle("Select Device"); 
   DevicePref.setSummary(mSelectedDevice); 
   deviceOptionsCat.addPreference(DevicePref); 

然后创建preferenceClickListner这里做StartActivityFromResult()

Then create OnPreferenceClickListner and here do StartActivityFromResult()

OnPreferenceClickListener onPreferenceClick = new Preference.OnPreferenceClickListener() {
       public boolean onPreferenceClick(Preference preference) {

           if (preference ==DevicePref )
           {
               Intent i = new Intent(DevuiceOptions.this,getDevice.class);  
               DevicePref.setIntent(i); 
               startActivityForResult(i,CHOOSE_DEVICE);

           }
           return true;
       }
   };

最后得到的结果手柄onActivityResult和更新汇总字段。

Finally to get the result handle onActivityResult and update Summary field.

@Override
   protected void onActivityResult(int requestCode, int resultCode, Intent data)
   {

       switch (requestCode) {

           case Constants.CHOOSE_DEVICE:
           {
               if (data!=null )
               {
                   Bundle b = data.getExtras();
                   mSelectedDevice =    (String) b.get("Name");
                   UpdatePreferences();
               }

           }
    }
}

感谢

这篇关于[机器人]如何从意图的结果,从preference屏幕推出?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-24 16:10