欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Android  listview數(shù)據(jù)顯示及提示信息的實例

 更新時間:2017年05月26日 10:44:50   投稿:lqh  
這篇文章主要介紹了Android listview數(shù)據(jù)顯示及提示信息的實例的相關(guān)資料,需要的朋友可以參考下

Android  listview數(shù)據(jù)顯示及提示信息的實例

最近我們測試人員說,我們的所有的列表都要做一個沒有數(shù)據(jù)就提示沒有數(shù)據(jù),當(dāng)時我的表情是這樣的 =_=!!! 我的天吶……這么多列表真的要一個一個做嘛?。。∪缓笪蚁肓艘幌?,那就直接改造Listview吧……說干就干。

沒有數(shù)據(jù)的效果:

有數(shù)據(jù)的效果:

代碼: NoDataListView.java

package com.tianjs.tianjinsuop2p.widgets;

import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.util.AttributeSet;
import android.widget.Adapter;
import android.widget.ListView;

import com.tianjs.tianjinsuop2p.R;

/**
 * Created by xiaolei on 2017/4/28.
 */

public class NoDataListView extends ListView
{
  private int height = 0;
  private int width = 0;
  private Bitmap noDataBitmap = null;
  private Paint mPaint;

  private int minItem = 0;
  private int noDataImgInt = 0;

  public NoDataListView(Context context)
  {
    this(context, null);
  }

  public NoDataListView(Context context, AttributeSet attrs)
  {
    this(context, attrs, 0);
  }

  public NoDataListView(Context context, AttributeSet attrs, int defStyleAttr)
  {
    super(context, attrs, defStyleAttr);
    TypedArray array = context.obtainStyledAttributes(attrs, R.styleable.NoDataListView);

    noDataImgInt = array.getResourceId(R.styleable.NoDataListView_noDataImg, 0);
    minItem = array.getInt(R.styleable.NoDataListView_minItem, 0);

    if (noDataImgInt != 0)
    {
      noDataBitmap = BitmapFactory.decodeResource(getResources(), noDataImgInt);
    } else
    {
      noDataBitmap = Bitmap.createBitmap(1, 1, Bitmap.Config.ARGB_8888);
    }
    mPaint = new Paint();

    array.recycle();
  }

  @Override
  protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec)
  {
    height = MeasureSpec.getSize(heightMeasureSpec);
    width = MeasureSpec.getSize(widthMeasureSpec);
    super.onMeasure(widthMeasureSpec, heightMeasureSpec);
  }

  @Override
  protected void onDraw(Canvas canvas)
  {
    Adapter adapter = getAdapter();
    super.onDraw(canvas);
    if (adapter == null || adapter.getCount() <= minItem)
    {
      canvas.drawBitmap(noDataBitmap, width / 2 - noDataBitmap.getWidth() / 2, height / 2 - noDataBitmap.getHeight() / 2, mPaint);
    }
  }
}

屬性聲明:

<declare-styleable name="NoDataListView">
  <!--最低Item數(shù)-->
  <attr name="minItem" format="integer"/>
  <!--沒有數(shù)據(jù)時,顯示的圖片資源-->
  <attr name="noDataImg" format="reference"/>
</declare-styleable>

如何使用?

<com.tianjs.tianjinsuop2p.widgets.NoDataListView
      android:id="@+id/listview"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:divider="#00000000"
      android:dividerHeight="0dp"
      android:overScrollMode="never"
      android:scrollbars="none"
      app:minItem="0"
      app:noDataImg="@drawable/icon_wushuju"/>

其實就是在onDraw里面,檢測到有幾個item,如果adapter為null,或者adapter的count小于等于最小item數(shù)的話,就在背景顯示沒有數(shù)據(jù)的圖片出來、

感謝閱讀,希望能幫助到大家,謝謝大家對本站的支持!

相關(guān)文章

  • Android放大鏡的實現(xiàn)代碼

    Android放大鏡的實現(xiàn)代碼

    這篇文章主要介紹了Android放大鏡的實現(xiàn)代碼,有需要的朋友可以參考一下
    2014-01-01
  • Android從源碼的角度徹底理解事件分發(fā)機(jī)制的解析(上)

    Android從源碼的角度徹底理解事件分發(fā)機(jī)制的解析(上)

    這篇文章主要介紹了Android從源碼的角度徹底理解事件分發(fā)機(jī)制的解析,具有很好的參考價值,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2018-05-05
  • Android調(diào)用OpenCV2.4.10實現(xiàn)二維碼區(qū)域定位

    Android調(diào)用OpenCV2.4.10實現(xiàn)二維碼區(qū)域定位

    這篇文章主要為大家詳細(xì)介紹了Android調(diào)用OpenCV 2.4.10實現(xiàn)二維碼區(qū)域定位,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2018-03-03
  • Android N 7.0中報錯:android.os.FileUriExposedException的解決方法

    Android N 7.0中報錯:android.os.FileUriExposedException的解決方法

    這篇文章主要給大家介紹了關(guān)于在Android N 7.0中報錯:android.os.FileUriExposedException的解決方法,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面來一起看看吧
    2018-05-05
  • Android實現(xiàn)簡單的分頁效果

    Android實現(xiàn)簡單的分頁效果

    這篇文章主要為大家詳細(xì)介紹了Android實現(xiàn)簡單的分頁效果,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2016-11-11
  • Android項目中使用HTTPS配置的步驟詳解

    Android項目中使用HTTPS配置的步驟詳解

    這篇文章主要給大家介紹了關(guān)于Android項目中使用HTTPS配置步驟的相關(guān)資料,文中介紹的非常詳細(xì),對大家具有一定的參考學(xué)習(xí)價值,需要的朋友們下面來一起看看吧。
    2017-06-06
  • Android三種網(wǎng)絡(luò)通訊方式及Android的網(wǎng)絡(luò)通訊機(jī)制

    Android三種網(wǎng)絡(luò)通訊方式及Android的網(wǎng)絡(luò)通訊機(jī)制

    在android平臺目前提供了三種網(wǎng)絡(luò)接口可以使用:分別是java.net.*(標(biāo)準(zhǔn)Java接口)、Org.apache接口和Android.net.*(Android網(wǎng)絡(luò)接口),本文主要給大家介紹android三種網(wǎng)絡(luò)通訊方式及android的網(wǎng)絡(luò)通訊機(jī)制,小伙伴們一起學(xué)習(xí)吧
    2015-11-11
  • Android使用OkHttp請求自簽名的https網(wǎng)站的示例

    Android使用OkHttp請求自簽名的https網(wǎng)站的示例

    本篇文章主要介紹了Android使用OkHttp請求自簽名的https網(wǎng)站的示例,非常具有實用價值,需要的朋友可以參考下、
    2017-09-09
  • Android實現(xiàn)視頻彈幕功能

    Android實現(xiàn)視頻彈幕功能

    這篇文章主要為大家詳細(xì)介紹了Android實現(xiàn)視頻彈幕功能,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2019-11-11
  • Android超簡單懸浮窗使用教程

    Android超簡單懸浮窗使用教程

    這篇文章主要介紹了Android超簡單懸浮窗使用教程,本文分步驟給大家介紹了使用前需要依賴庫,給大家介紹的非常詳細(xì),需要的朋友可以參考下
    2021-09-09

最新評論