2014-01-20 3 views
-1

Извините за мой английский.Этикетки пропусков (с идентификатором) не меняются при изменении конфигурации

У меня есть активность.

Схема деятельности:

<?xml version="1.0" encoding="utf-8"?> 

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" > 

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

     <FrameLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:id="@+id/containerOfStandardFilters" /> 

     <FrameLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:id="@+id/containerOfMoreFilters" /> 


    </LinearLayout> 

</ScrollView> 

В коде деятельности я динамически заполнить обе раскладки контейнеров. В настоящее время я заполняю только containerOfStandardFilters.

Layout, который я использовал, чтобы раздуть содержание containerOfStandardFilters:

<?xml version="1.0" encoding="utf-8"?> 

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

    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_gravity="center_horizontal" 
     android:textSize="@dimen/textSizeOfFilterGroupTitle" 
     android:text="@string/titleOfSortingGroup" /> 

    <CheckBox 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:textSize="@dimen/textSizeOfSortingGroupItems" 
     android:text="@string/labelOfSortByDistanceCheckBox" 
     android:id="@+id/sortByDistanceCheckBox" /> 

    <CheckBox 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:textSize="@dimen/textSizeOfSortingGroupItems" 
     android:text="@string/labelOfSortByDiscountCheckBox" 
     android:id="@+id/sortByDiscountCheckBox" /> 

    <TextView 
     android:layout_width="match_parent" 
     android:layout_height="@dimen/sizeBetweenFilterGroups" /> 

    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_gravity="center_horizontal" 
     android:textSize="@dimen/textSizeOfFilterGroupTitle" 
     android:text="@string/titleOfPaymentMethodGroup"/> 

    <CheckBox 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:textSize="@dimen/textSizeOfSortingGroupItems" 
     android:text="@string/labelOfCashlessPaymentsCheckBox" 
     android:id="@+id/cashlessPaymentsCheckBox" /> 

    <TextView 
     android:layout_width="match_parent" 
     android:layout_height="@dimen/sizeBetweenFilterGroups" /> 

    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_gravity="center_horizontal" 
     android:textSize="@dimen/textSizeOfFilterGroupTitle" 
     android:text="@string/titleOfWorkingHoursGroup"/> 

    <CheckBox 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:textSize="@dimen/textSizeOfSortingGroupItems" 
     android:text="@string/labelOfWorksNowCheckBox" 
     android:id="@+id/worksNowCheckBox" /> 

    <TextView 
     android:layout_width="match_parent" 
     android:layout_height="@dimen/sizeBetweenFilterGroups" /> 

    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_gravity="center_horizontal" 
     android:textSize="@dimen/textSizeOfFilterGroupTitle" 
     android:text="@string/titleOfDiscountTypeGroup" /> 

    <CheckBox 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:textSize="@dimen/textSizeOfSortingGroupItems" 
     android:text="@string/labelOfBonusCheckBox" 
     android:id="@+id/bonusCheckBox" /> 

    <CheckBox 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:textSize="@dimen/textSizeOfSortingGroupItems" 
     android:text="@string/labelOfDiscountCheckBox" 
     android:id="@+id/discountCheckBox" /> 

    <CheckBox 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:textSize="@dimen/textSizeOfSortingGroupItems" 
     android:text="@string/labelOfCashBackCheckBox" 
     android:id="@+id/cashBackCheckBox" /> 

</LinearLayout> 

Но если изменить текущий язык (через настройки) и возвращается к активности фильтра (от активности системы настройки), то только вид без идентификатора будет обновляться этикетки.

Как я могу решить свою проблему?

+0

Почему "-1" ???? ????? –

+0

Значение значения с идентификатором сохраняется при изменении конфигурации. Также вы можете реализовать код с помощью фрагментов и добавить их в свой xml вместо макетов фреймов – vamsiampolu

ответ

0

Извините за мой английский.

В конце концов я решил этот вопрос следующим образом.

я обернут каждый View с text и id атрибутами в FrameLayout с тем же атрибутом id и удалены id от каждого такого View.

Но, правда, код для поиска View усложнился.

В layout вместо использования:

<CheckBox 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="@string/labelOfCheckBox" 
    android:id="@+id/checkBox" /> 

Я использую:

<FrameLayout 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:id="@+id/checkBox" > 

    <CheckBox 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="@string/labelOfCheckBox" /> 

</FrameLayout> 

И код, чтобы найти завернутые Views:

public class MyActivity extends Activity { 
    public View findWrappedView(int id) { 
     ViewGroup container = (ViewGroup) findViewById(id); 
     return container.getChildAt(0); 
    } 
} 
Смежные вопросы