2010-08-13 6 views
0

Имея еще одну проблему, и это ВАФЛИНГ!Динамическое добавление просмотров и сбоев

Здесь мы идем.

У нас есть макет ...

<?xml version="1.0" encoding="utf-8"?> 
<!-- Template for creating a result in MediaUpload --> 
<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:orientation="vertical"> 
    <LinearLayout 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:orientation="horizontal" 
     android:isScrollContainer="true" 
     android:focusableInTouchMode="false" 
     android:focusable="false"> 
     <ImageView android:id="@+id/imgView" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:maxWidth="110dp" 
     android:maxHeight="110dp" 
     android:minWidth="110dp" 
     android:minHeight="110dp" 
     android:layout_gravity="center_vertical" 
     android:padding="3dp" 
     android:scaleType="center" 
     android:clickable="true" 
     android:focusable="true" 
     android:focusableInTouchMode="true" 
     android:saveEnabled="true"/> 
     <LinearLayout 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:orientation="vertical" 
     android:gravity="center_horizontal"> 
     <TextView android:id="@+id/img_file_name" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:textColor="@color/LinkText" 
     android:textStyle="bold" 
     android:paddingBottom="3dp"/> 
     <EditText android:id="@+id/img_title" 
     android:hint="Title" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:minWidth="150dp" 
     android:maxHeight="50dp" 
     android:inputType="textVisiblePassword" 
     android:maxLength="255"/> 
     <EditText android:id="@+id/img_desc" 
     android:hint="Description" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:minWidth="150dp" 
     android:maxHeight="50dp" 
     android:maxLength="255"/> 
     </LinearLayout> 
    </LinearLayout> 
    <ImageView 
     android:src="@drawable/divider" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:scaleType="fitXY" 
     android:paddingTop="2dp" 
     android:paddingBottom="2dp"> 
    </ImageView> 
</LinearLayout> 

Мы используем это здесь в качестве шаблона для объекта, который пользователь может загрузить на наш сайт. (Это массивная компоновка, поэтому просто отправляем то, что мы добавляем).

<LinearLayout android:id="@+id/list_of_images" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:orientation="vertical"> 
</LinearLayout> 

Су ... Вот настоящая проблема. Когда пользователь выбирает изображение из своей галереи, он правильно добавляет наш LinearLayout. Теперь у одного из наших сотрудников постоянно возникают проблемы с памятью, и приложение закрывается, когда он фотографирует или просматривает. Наше приложение настроено на сохранение всех данных (данных Uri, текста заголовка, текста описания и т. Д.) Непосредственно перед тем, как пользователь покинет приложение в методе savedInstanceState.

/* 
    * The Activity is being recycled and needs to have its instance 
    * saved before we lost all of the image URis! 
    */ 
    protected void onSaveInstanceState(Bundle outState) 
    { 
     super.onSaveInstanceState(outState); 
     helper.saveEnteredData(); 
     outState.putParcelableArray(IMAGE_URI_BUNDLE_KEY, helper.getUploadObjectArray()); 
     outState.putParcelable(CAPTURE_IMAGE_URI_BUNDLE_KEY, currentFileURI); 

     outState.putInt(CURRENT_JOB_BUNDLE_KEY, reportSpinner.getSelectedItemPosition()); 

     ArrayList<ReportInfoParcelable> alReps = new ArrayList<ReportInfoParcelable>(); 
     for(int i = 0; i < reportList.length; ++i) 
      alReps.add(new ReportInfoParcelable(reportList[i])); 

     outState.putParcelableArray(JOB_LIST_BUNDLE_KEY, alReps.toArray(new ReportInfoParcelable[alReps.size()])); 
    } 

Вот helper.saveEnteredData() ...

public void saveEnteredData() 
    { 
     ViewGroup vg = null; 
     UploadObject object = null; 
     String title, desc; 
     for(int i = 0; i < mLinearLayout.getChildCount(); i++) 
     { 
      vg = (ViewGroup) mLinearLayout.getChildAt(i); 
      object = alUploadObjects.get(i); 
      title = ((TextView) vg.findViewById(R.id.img_title)).getText().toString(); 
      desc = ((TextView) vg.findViewById(R.id.img_desc)).getText().toString(); 
      object.setTitle(title); 
      object.setDesc(desc); 
     } 
    } 

Когда приложение возвращается из аварии после того, как пользователь покинул свою деятельность, когда мы отлаживать через приложение по возвращении, то массив возвращаемых объектов UploadObjects содержат все правильные названия, заголовки и описания Uri, но когда приложение окончательно отображает, ALL editTexts на LinearLayout, к которому мы добавляем, все внезапно содержат заголовок и описание последнего UploadObject в массиве Parcelable. Опять же, мы отлаживаем каждое добавление объектов, а объекты содержат правильные данные. Мы сбиты с толку и нуждаемся в помощи здесь!

+0

В качестве дополнительного комментария, поскольку мы восстанавливаемся после сбоя, в методе onCreate мы анализируем массив ReportInfoParcelable. Данные там, опять же, верны. – DavidAndroidDev

ответ

0

Мы получили его!

Не совсем уверен, что здесь происходит, но мы переопределили (sp?) Метод onPostCreate (Bundle) и проанализировали здесь пакет, и наша проблема исправлена. Должно быть что-то о раздувании xml-файла во время onCreate(), который что-то путает.

В любом случае, если вам нужно раздуть XML (кроме обычного макета), сделайте это onPostCreate()!

Смежные вопросы