how to access widgets set in layout using preference activity

ぃ、小莉子 提交于 2019-12-04 15:52:36

you need to use your mention your preference class in xml layout like the below code

<PreferenceCategory
   android:key="more_category"
   android:title="More Wallpapers " >

   <com.myapp.myclass  android:key="more_apps"/>

</PreferenceCategory>

com.myapp is a package name and myclass is java file where all your coding comes..

Here is the java code and inflated xml more_apps.xml

  public class myclass extends Preference {

    public myclass(Context context) {
    super(context);
    // TODO Auto-generated constructor stub
    }

@Override
protected View onCreateView(ViewGroup parent) {
    // TODO Auto-generated method stub

    LayoutInflater inflater = (LayoutInflater) getContext()
            .getSystemService(Context.LAYOUT_INFLATER_SERVICE);

    View view = inflater.inflate(R.layout.more_apps, null);

    return view;
  }

 }

This way you can create your custom preference activity and do any stuff..

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