2012-02-07 3 views
0

TextView 객체에 텍스트가없는 경우 ListView 행에서 사라 지도록 TextView 객체를 설정하려고합니다.ListView에서 텍스트를 동적으로 숨기기 - 항상 작동하지 않음

@Override 
public View getView(int position, final View convertView, ViewGroup parent) { 

    View row = convertView; 

    if (row == null) { 
     final LayoutInflater inflater = getLayoutInflater(); 
     row = inflater.inflate(R.layout.members, parent, false); 
    } 

    final TextView header = (TextView) row.findViewById(R.id.listHeader); 
    header.setText(parsedList.get(position).header); 

    final TextView footer = (TextView) row.findViewById(R.id.listDescription); 

    if(parsedList.get(position).footer.length() == 0) { 
     footer.setVisibility(View.GONE); 
    } else { 
     footer.setText(parsedList.get(position).footer); 
    } 

    return row; 
} 

매니페스트 :

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="fill_parent" 
android:layout_height="wrap_content" 
android:orientation="vertical"> 
    <TextView 
    android:id="@+id/listHeader" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:text="" 
    android:textAppearance="?android:attr/textAppearanceLarge" android:layout_marginLeft="12dp" android:layout_marginRight="12dp" android:layout_marginTop="6dp" android:layout_marginBottom="6dp"/> 
    <TextView 
    android:id="@+id/listDescription" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:text="" 
    android:textAppearance="?android:attr/textAppearanceSmall" android:layout_marginBottom="6dp" android:layout_marginLeft="24dp" android:layout_marginRight="12dp"/> 

</LinearLayout> 

때 정상적으로 활동로드, 모든 디스플레이 (대부분). 그러나 화면을 회전하면 바닥 글 TextView 객체 중 일부가 화면에서 사라집니다. 심지어 디버거를 실행할 때 footer.setVisibility(View.GONE); 절대로 호출되는 경우에도이 있습니다.

또한 내 매니페스트에는 android:configChanges="orientation|keyboardHidden"이 활동으로 설정되어 있습니다.

편집 :이 문제는 활동이 생성 될 때 거의 발생하지 않습니다. 그러나 항상 화면 회전에서 발생합니다.

+0

그런 상태가 될 수 있습니다! 당신은 그것을 점검 했느냐! – Navdroid

+1

if 조건 바로 앞에'footer.setVisibility (View.VISIBLE);를 넣으십시오. – Luksprog

+0

Slukian의 솔루션이 효과가있었습니다. 감사. – Khronos

답변

1

바꿀 내용.

if(parsedList.get(position).footer.length() == 0) { 
     footer.setVisibility(View.GONE); 
    } else { 
     footer.setText(parsedList.get(position).footer); 
     footer.setVisibility(View.VISIBLE); 
    } 
0

재정 활동에서이 방법.

@Override 
public void onConfigurationChanged(Configuration newConfig) { 
    super.onConfigurationChanged(newConfig); 
} 
+0

메인 페스트에서 : android : configChanges = "keyboard | keyboardHidden | 오리엔테이션" –

+0

나에게 적합하지 않았습니다. 문제가 아직 있습니다. – Khronos

+0

레이아웃을 선형 레이아웃에서 ScrollView로 변경하십시오. –

0

당신이 if 문에서 gettext에() 길이()를 사용하여 시도?

if(parsedList.get(position).footer.length() == 0) 
관련 문제