Last active
February 10, 2018 22:31
-
-
Save slightfoot/5519281 to your computer and use it in GitHub Desktop.
Example of the use of a ListView with associated empty View.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | |
xmlns:tools="http://schemas.android.com/tools" | |
android:layout_width="match_parent" | |
android:layout_height="match_parent" | |
android:orientation="vertical" | |
tools:context=".MainActivity" | |
> | |
<Button | |
android:id="@+id/button" | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:layout_gravity="center_horizontal" | |
android:text="@string/refresh" | |
/> | |
<FrameLayout | |
android:layout_width="match_parent" | |
android:layout_height="0dp" | |
android:layout_weight="1" | |
> | |
<ListView | |
android:id="@android:id/list" | |
android:layout_width="match_parent" | |
android:layout_height="match_parent" | |
/> | |
<TextView | |
android:id="@android:id/empty" | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:layout_gravity="center" | |
android:textAppearance="?android:textAppearanceMedium" | |
android:text="@string/empty" | |
/> | |
</FrameLayout> | |
</LinearLayout> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<resources> | |
<string name="empty">Empty</string> | |
<string name="refresh">Refresh</string> | |
</resources> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.ArrayList; | |
import java.util.Random; | |
import android.app.ListActivity; | |
import android.content.Context; | |
import android.content.Intent; | |
import android.os.Bundle; | |
import android.view.View; | |
import android.widget.ArrayAdapter; | |
public class TestActivity extends ListActivity | |
{ | |
public static Intent createIntent(Context context) | |
{ | |
return new Intent(context, TestActivity.class); | |
} | |
@Override | |
protected void onCreate(Bundle savedInstanceState) | |
{ | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_list); | |
findViewById(R.id.button).setOnClickListener(new View.OnClickListener() | |
{ | |
@Override | |
public void onClick(View v) | |
{ | |
refreshAlbumList(); | |
} | |
}); | |
refreshAlbumList(); | |
} | |
public void refreshAlbumList() | |
{ | |
setListAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, getAlbumList())); | |
} | |
private ArrayList<String> getAlbumList() | |
{ | |
ArrayList<String> list = new ArrayList<String>(); | |
if(new Random().nextBoolean()){ | |
list.ensureCapacity(100); | |
for(int i = 0; i < 100; i++){ | |
list.add("Album Name " + (i + 1)); | |
} | |
} | |
return list; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@HologramOfMe I really agree with you