There are two ways of doing this:
1. layout file Activity_mian.xml need to add a ListView control, and the ID is list, otherwise it will not run, it should be because preferenceactivity is a list.
<?xml version= "1.0" encoding= "Utf-8"? ><linearlayout xmlns:android= "Http://schemas.android.com/apk/res/android"Android:layout_width= "Fill_parent"Android:layout_height= "Fill_parent"android:orientation= "Vertical" > <TextView android:layout_width= "Fill_parent"Android:layout_height= "Wrap_content"Android:text= "@string/hello"/> <ListView Android:id= "@android: Id/list"Android:layout_width= "Fill_parent"Android:layout_height= "Wrap_content"Android:layout_weight= "1"Android:drawselectorontop= "false"/></linearlayout>
2. Add Setcontentview (R.layout.activity_main) directly to the activity in the oncreate of the activity;
You can then use Findviewbyid to get the controls under the custom layout.
Another way:
1. Add the Preferencescreen layout in the XML file
<preference android:layout="@layout/activity_main" android:key="Youmi _ad"/>
2.activity_mian.xml is the same as before
3. Findpreference ("main");