源码网商城,靠谱的源码在线交易网站 我的订单 购物车 帮助

源码网商城

Android 处理空列表的方法(必看篇)

  • 时间:2020-06-08 12:50 编辑: 来源: 阅读:
  • 扫一扫,手机访问
摘要:Android 处理空列表的方法(必看篇)
android中ListView 用来展示数据,如果列表为空的状态,可以通过setEmpty(View)方法设置为空时显示的内容。 [img]http://files.jb51.net/file_images/article/201704/20170418101154.jpg[/img] [b]布局xml[/b]
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent"
  android:orientation="vertical" >

  <ListView
    android:id="@+id/my_list_view"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" />

  <ImageView
    android:id="@+id/empty_view"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:src="@drawable/empty_view" />

</FrameLayout>
[b]代码:[/b]
public class Hack24Activity extends Activity {
  private ListView mListView;
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_hack24);

    mListView = (ListView) findViewById(R.id.my_list_view);
    mListView.setEmptyView(findViewById(R.id.empty_view));

  }
}
以上这篇Android 处理空列表的方法(必看篇)就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持编程素材网。
  • 全部评论(0)
联系客服
客服电话:
400-000-3129
微信版

扫一扫进微信版
返回顶部