Имея немного проблем с пустым ListView в android. Вот что я получил:Как обрабатывать пустой ListView в android?
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
}
}
То, что я попытался это:
this.getListView().setEmptyView(findViewById(android.R.id.empty));
А потом вставив TextView с идентификатором пустым в main_activity.xml Но результат в том, что взял на экране и я не мог видеть список.
Текущий 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>
Простой способ будет объявить еще один TextView прямо под ListView, контролируя при этом его видимость динамически с помощью кодов. –