Android layout preferenceactivity--Insert layout file

Source: Internet
Author: User

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");

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.