JAVA/안드로이드

Preference 안에 Layout 만들기

룰루릴리 2016. 7. 6. 12:38
1. PreferenceScreen 추가 
2. Preference를 상속해서 클스추가.
3. Preference의 아이템으로 TestActivity 추가 추가. 


preference.xml 

<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<com.TestActivity
android:title="test
android:key="key_test/>

</PreferenceScreen>



test_activity.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">

<TextView
android:id="@+id/text_test
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="test/>
</LinearLayout>





 TestActivity.xml
public class TestActivity extends Preference {

    Context mContext;
    //외부에서 접근.
    static View viewTest;

    TestActivity    {
        this(context, attrs,0);
        this.mContext = context;
    }

    public TestActivity (Context context, AttributeSet attrs, int defStyle)    {
        super(context, attrs, defStyle);
        this.mContext = context;
        setLayoutResource(R.layout.test_activity);
    }


    @Override
    protected void onBindView(View view) {
        super.onBindView(view);
        viewTest = view;
        TextView textTest = (TextView)view.findViewById(R.id.text_test);
   }
}