Starting custom PreferenceActivity INSIDE another PreferenceActivity

淺唱寂寞╮ 提交于 2019-12-24 00:33:54

问题


Inside my Configuration activity i need to create a preference screen with a fixed View at the top showing a preview of content configured in the page. I don't want to change the main preference screen (i have already a separate activity for that) i want a different layout for a "nested" preferencescreen.

What i've tried is specifying an Intent inside the preference screen however when i click on this options nothing happens and activity goes into timeout... Activity is correctly configured on the manifest (and extends ConfigureActivity as the main one does).

  <PreferenceScreen 
    android:key="inner"
    android:title="Title" 
    android:summary="Summary"
    >
    <intent 
      android:action="android.appwidget.action.APPWIDGET_CONFIGURE" 
      android:targetPackage="my.package.lib" 
      android:targetClass="my.package.lib.ConfigureClass" 
      />
  </PreferenceScreen>

Another idea could be creating a custom "preference" that launches another configuration activity, could this work? Would be correct/acceptable to have multiple configuration activities?


回答1:


The following code on the main ConfigureActivity works however i don't know if its a clean way to do what i want. Could someone confirm?

PreferenceScreen b = (PreferenceScreen) findPreference("my_empty_preference_screen");       
b.setOnPreferenceClickListener(new OnPreferenceClickListener() {
    @Override
    public boolean onPreferenceClick(Preference preference) {
        Intent intent = new Intent(ConfigureActivity.this, ConfigureActivity.class); 
        intent.setAction("android.appwidget.action.APPWIDGET_CONFIGURE");
        ConfigureActivity.this.startActivity(intent);
        return false;
    }
});


来源:https://stackoverflow.com/questions/4681360/starting-custom-preferenceactivity-inside-another-preferenceactivity

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!