Ans*_*hul 4 android android-layout android-activity
我有一个Listview来显示一些项目,我也使用了一个空视图,以防我的适配器没有listview的项目显示.问题是当我去这个活动时,它首先在屏幕上显示空视图一秒钟然后加载项目并在列表视图中显示它们.
我的活动onCreate看起来像这样:
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.favorite_exams);
list = (ListView) findViewById(R.id.favoriteExamsList);
View empty = findViewById(R.id.favoriteExamsListEmptyView);
list.setEmptyView(empty);
new readingFavFileTask().execute(UtilityFuctions.FAV_EXAMS_FILE_NAME);
}
Run Code Online (Sandbox Code Playgroud)
我的布局文件是:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<ListView
android:id="@+id/favoriteExamsList"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
</ListView>
<LinearLayout
android:id="@+id/favoriteExamsListEmptyView"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:visibility="gone" >
<TextView
android:id="@+id/favoriteExamsEmptyViewMessage"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:text="You do not have any favorite Exams.Please add Exams using below button."
android:textSize="20dp" />
<Button
android:id="@+id/favoriteExamsAdd"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:onClick="onClickAddExams"
android:text="Add Exams"
>
</Button>
</LinearLayout>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
如果我们在我们的适配器中有数据,我如何确保空视图永远不会显示一秒钟.我应该在检查适配器之后将空视图附加到列表中,还是以任何其他方式执行此操作?
我找到了答案.list.setEmptyView(empty)在将我的适配器设置为list后,我只需要在我的AsyncTask onPostExecute()方法中应用Empty View ,它就可以正常工作.
| 归档时间: |
|
| 查看次数: |
3138 次 |
| 最近记录: |