2013-05-04 6 views
1

안드로이드에서 비어있는 ListView를 다루는데 약간의 문제가 있습니다. 화면을 인수하는안드로이드에서 비어있는 ListView를 처리하는 방법?

this.getListView().setEmptyView(findViewById(android.R.id.empty)); 

그리고 main_activity.xml 에 빈 ID로 텍스트 뷰를 삽입하지만 결과는했다 : 나는 무엇을 시도했다

public class MainActivity extends ListActivity { 
... 
refreshList(); 
...} 


public void refreshAlbumList(){ 
    albumList=control.listAlbums(); 

    if (albumList.length!=0){ 
     ArrayAdapter<String> ap = new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,albumList); 
     setListAdapter(ap); 
    }else{  
     //deal with empty list somehow, currently results in error 
    } 
} 

는 : 여기있어 무엇 목록을 볼 수 없었습니다.

현재 XML :

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
xmlns:android1="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:orientation="horizontal" 
tools:context=".MainActivity" > 

<ListView 
    android1:id="@id/android:list" 
    android1:layout_width="match_parent" 
    android1:layout_height="wrap_content" 
    android1:layout_weight="1" > 
</ListView> 

</LinearLayout> 
+0

쉬운 방법은 바로 목록보기에서 다른 텍스트 뷰를 선언 할 것입니다. –

답변

2

목록보기는/숨기기 자체와 빈보기를 표시할지 여부를 결정하기 위해 ListAdapter # IsEmpty 함수 메소드를 호출합니다. 따라서 항상 ListAdapter를 설정해야합니다.

그래서 대답은 항상 ArrayAdapter를 만들고 항상 ListView로 설정하는 것입니다. 귀하의 활동에 전화 ListView # setEmptyView 메서드를 호출합니다. 또는, android : id = "@ android : id/empty"속성을 갖는 TextView를 간단히 가질 수 있으며, ListActivity는이를 감지하고 위의 메소드를 사용하여 할당합니다.

예 : 코드를 통해 동적으로 가시성을 제어하면서 https://gist.github.com/slightfoot/5519281

+0

불행히도 작동하지 않습니다. 내 코드를 넣을 때 한 실수 - 난 실제로이 일을 : this.getListView(). setEmptyView (findViewById (android.R.id.empty)); 그리고 그게 textview xml과 함께 작동하지 않습니다. – Zima

+0

내가 제안한대로 어댑터가 설정되고 있는지 확인 했습니까? – Simon

+0

나는 아직도 행운이 없었다. – Zima

관련 문제