2014-09-23 53 views
0
public static void loadPopupData(Context context, final ListView listView) { 
     final DataBaseManager dbManager1 = new DataBaseManager(context); 
     final ArrayList<Notify> notifies = dbManager1.getNotificationList(15); 

     Notifcationadapter adapter = new Notifcationadapter(context, notifies); 
     listView.setAdapter(adapter); 
     listView.setEmptyView(emptyView); 
    } 

ListView中發現的物品這種方法是用它來打印數據列表視圖:如何顯示不在機器人

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/popup" 
    android:layout_width="fill_parent" 
    android:layout_height="350dip" > 

    <RelativeLayout 
     android:id="@+id/rl_top" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_alignParentTop="true" 
     android:layout_marginTop="10dp" 
     android:background="#00000000" > 

     <ImageView 
      android:id="@+id/image_tringle" 
      android:layout_width="40px" 
      android:layout_height="21px" 
      android:layout_alignParentRight="true" 
      android:layout_alignParentTop="true" 
      android:layout_marginRight="50dp" 
      android:src="@drawable/notficationarrow_icon" /> 
    </RelativeLayout> 

    <ListView 
     android:id="@+id/listView1" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:layout_below="@id/textView1" 
     android:background="@anim/notifcationitembroder" > 
    </ListView> 
<TextView android:id="@+id/emptyView" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:layout_alignTop="@+id/listView1" 
    android:layout_alignBottom="@+id/listView1" 
    android:gravity="center" 
    android:visibility="invisible" 
    android:text="No items in list" /> 
    <TextView 
     android:id="@+id/textView1" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_alignParentLeft="true" 
     android:layout_below="@+id/rl_top" 
     android:background="@drawable/bgnotifcationlayoutback" 
     android:gravity="center" 
     android:paddingBottom="20dp" 
     android:text="Notification" 
     android:textColor="#666666" 
     android:paddingTop="2dp" 
     android:textSize="20dip" 
     android:textStyle="bold" /> 

</RelativeLayout> 

這是我在哪裏打印列表視圖的XML文件。

我想在Listview中沒有項目的時候它應該顯示沒有找到Listview我試圖做但是無法顯示它請建議我如何顯示如果在列表視圖中沒有項目時沒有找到項目。

+0

只要檢查'arraylist.length()== 0'是否顯示你想要的東西。 – Piyush 2014-09-23 05:06:20

回答

0

請在你的XML

<TextView android:id="@android:id/empty" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:text="No Results" /> 

添加這個和這個代碼在您的活動包含列表

public static void loadPopupData(Context context, final ListView listView) { 
     final DataBaseManager dbManager1 = new DataBaseManager(context); 
     final ArrayList<Notify> notifies = dbManager1.getNotificationList(15); 

     Notifcationadapter adapter = new Notifcationadapter(context, notifies); 
     listView.setAdapter(adapter); 
     listView.setEmptyView(findViewById(android.R.id.empty)); 
    } 
+0

沒有它的不工作plz檢查我的代碼然後編輯我的代碼 – user2794306 2014-09-23 04:26:17

+0

@ user2794306嘗試此代碼 – sam 2014-09-23 04:38:03

+0

我已編輯的代碼.. plz檢查 – user2794306 2014-09-23 07:28:40

0

試試這個一。如果這不是你的解決方案,否則增加一個視圖中顯示沒有任何記錄顯示

public String[] getSociety() { 
    int pos = 0; 
    MFDbBHelper mDbHelper = new MFDbBHelper(this); 
    List<Society> society = mDbHelper.getAllSociety(); 
    String[] values = null; 
    if (society.size() > 0) { 

     values = new String[society.size()]; 
     for (Society socty : society) { 

      values[pos] = socty.get_society_name(); 

      // Writing Society to log 
      String log = "Id: " + socty.get_society_id() + " ,Name: " 
        + socty.get_society_name(); 
      Log.d("Insert: ", log); 

      pos++; 
     } 
    } else { 

     values = new String[0]; 
     values[0] = "No records found!"; 
    } 
    return values; 

} 
0

添加一個文本視圖,顯示在彈出的xml文件「無結果」,並給它一個ID。

像這樣

<TextView android:id="@+id/emptyView" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:layout_alignTop="@+id/listView1" 
    android:layout_alignBottom="@+id/listView1" 
    android:gravity="center" 
    android:text="No items in list" 
    android:visibility="invisible"/> 

而在代碼部分設置的TextView作爲你的ListView emptyview。

public static void loadPopupData(Context context, final ListView listView) { 
     final DataBaseManager dbManager1 = new DataBaseManager(context); 
     final ArrayList<Notify> notifies = dbManager1.getNotificationList(15); 

     Notifcationadapter adapter = new Notifcationadapter(context, notifies); 
     listView.setAdapter(adapter); 
     listView.setEmptyView(findViewById(R.id.emptyView)); 
    } 
+0

但在Listview項目中獲取數據後,textview android:text =「列表中沒有項目」不會消失 – user2794306 2014-09-23 06:06:41

+0

然後保持textview默認情況下不可見。更新了我的答案。 – 2014-09-23 06:16:53

+0

更改後你的代碼我Listview看起來像這樣當我添加你的代碼http://snag.gy/Zc7jK.jpg – user2794306 2014-09-23 06:25:01