2014-09-10 2 views
0

Это код ListViewкак не установить пункт NO найден в ListView если нет пункт в списке андроида

listView = (ListView) layout.findViewById(R.id.listView1); 
     Notifcationadapter adapter = new Notifcationadapter(this, notifies); 
     listView.setAdapter(adapter); 
     TextView emptyText = (TextView)findViewById(android.R.id.empty); 
     listView.setEmptyView(emptyText); 
     listView.setOnItemClickListener(this); 

это мой list.xmlfile:

<?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:background="#00000000" > 

     <ImageView 
      android:id="@+id/image_tringle" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      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/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:text="Notification" 
     android:textColor="#666666" 
     android:textSize="25dip" 
     android:textStyle="bold" /> 

</RelativeLayout> 

Это мой просмотр список адептер класс:

public class Notifcationadapter extends BaseAdapter { 
    private static ArrayList<Notify> values; 
    Context context; 
    String senderid; 
    String imagepath; 

    // List<RowItem> rowItems; 
    ViewHolder holder = null; 

    LinearLayout linear2; 

    DataBaseManager dbManager = new DataBaseManager(context); 
    ArrayList<Notify> notifies; 

    public Notifcationadapter(Context context, ArrayList<Notify> notifies) { 
     super(); 
     this.context = context; 
     this.notifies = notifies; 

    } 

    /* private view holder class */ 
    private class ViewHolder { 

     TextView txtTitle; 
     TextView txtDesc; 
     ImageView yesimage; 

     ImageView noimage; 
     TextView revresetime; 

     TextView rejected; 
     ImageView notificationuserimage; 
     LinearLayout linear2; 

    } 

    public View getView(int position, View convertView, ViewGroup parent) { 

     LayoutInflater mInflater = (LayoutInflater) context 
       .getSystemService(Activity.LAYOUT_INFLATER_SERVICE); 
     if (convertView == null) { 
      convertView = mInflater.inflate(R.layout.notifcationlistitem, 
        parent, false); 
      holder = new ViewHolder(); 
      // holder.linear2 = (LinearLayout) convertView 
      // .findViewById(R.id.linear2); 
      holder.txtDesc = (TextView) convertView.findViewById(R.id.desc); 

      holder.txtTitle = (TextView) convertView.findViewById(R.id.title); 
      holder.yesimage = (ImageView) convertView 
        .findViewById(R.id.imageView1); 
      holder.noimage = (ImageView) convertView 
        .findViewById(R.id.imageView2); 
      holder.revresetime = (TextView) convertView 
        .findViewById(R.id.revresetime); 
      holder.rejected = (TextView) convertView 
        .findViewById(R.id.rejectedrequest); 
      holder.notificationuserimage = (ImageView) convertView 
        .findViewById(R.id.notificationuserimage); 
      convertView.setTag(holder); 
     } else { 
      holder = (ViewHolder) convertView.getTag(); 
     } 

     // holder.txtTitle.setText("Title"); 
     String statustype = notifies.get(position).getNotificationType(); 

     if (statustype.equals("1")) { 

      holder.txtDesc.setText(notifies.get(position) 
        .getNotificationDescrpiton()); 

      holder.revresetime.setText(Functions 
        .setLastSeenNotifcationTime(notifies.get(position) 
          .getNotificationDatetime())); 
      holder.txtTitle.setText("Request For travelling"); 

      senderid = notifies.get(position).getNotificationSenderID(); 
      imagepath = "http://api.lociiapp.com/TransientStorage/" 

      + senderid + ".jpg"; 
      AQuery aq = new AQuery(context); 

      aq.id(holder.notificationuserimage).image(imagepath); 

      holder.yesimage.setVisibility(View.VISIBLE); 
      holder.noimage.setVisibility(View.VISIBLE); 

      holder.yesimage.setTag(convertView); 
      holder.yesimage.setOnClickListener(new OnClickListener() { 

       @Override 
       public void onClick(View arg0) { 
        // TODO Auto-generated method stub 
        View parentView = (View) arg0.getTag(); 
        View view = parentView.findViewById(R.id.imageView1); 
        view.setVisibility(View.GONE); 
        view = parentView.findViewById(R.id.imageView2); 
        view.setVisibility(View.GONE); 
        // view = parentView.findViewById(R.id.linear2); 
        view.setVisibility(View.INVISIBLE); 
        view = parentView.findViewById(R.id.runnimage); 
        view.setVisibility(View.INVISIBLE); 
        Toast.makeText(context, "Yes", 10000).show(); 

       } 
      }); 
      holder.noimage.setTag(convertView); 
      holder.noimage.setOnClickListener(new OnClickListener() { 

       @Override 
       public void onClick(View v) { 
        // TODO Auto-generated method stub 
        View parentView = (View) v.getTag(); 
        View view = parentView.findViewById(R.id.imageView1); 
        view.setVisibility(View.GONE); 
        view = parentView.findViewById(R.id.imageView2); 
        view.setVisibility(View.GONE); 
        view = parentView.findViewById(R.id.rejectedrequest); 
        view.setVisibility(View.VISIBLE); 
        Toast.makeText(context, "NO", 10000).show(); 
        // holder.linear2.setVisibility(View.INVISIBLE); 
        holder.yesimage.setVisibility(View.GONE); 
        holder.noimage.setVisibility(View.GONE); 
        holder.rejected.setVisibility(View.VISIBLE); 
       } 
      }); 

     } 

     else { 

      holder.txtDesc.setText(notifies.get(position) 
        .getNotificationDescrpiton()); 
      holder.txtTitle.setText("Post"); 
      holder.revresetime.setText(Functions 
        .setLastSeenNotifcationTime(notifies.get(position) 
          .getNotificationDatetime())); 

      senderid = notifies.get(position).getNotificationSenderID(); 
      imagepath = "http://api.lociiapp.com/TransientStorage/" 

      + senderid + ".jpg"; 
      AQuery aq = new AQuery(context); 
      aq.id(holder.notificationuserimage).image(imagepath); 

      holder.yesimage.setVisibility(View.GONE); 
      holder.noimage.setVisibility(View.GONE); 
     } 

     String notisread = notifies.get(position).getNotificationStatus(); 
     if (notisread.equals("false")) { 

      convertView.setBackgroundColor(Color.parseColor("#ffffff")); 
     } else { 
      convertView.setBackgroundColor(Color.parseColor("#f5f6f1")); 
     } 

     return convertView; 
    } 

    @Override 
    public int getCount() { 
     return notifies.size(); 
    } 

    @Override 
    public Object getItem(int position) { 
     return notifies.get(position).getNotificationType(); 
    } 

    @Override 
    public long getItemId(int position) { 
     return position; 
    } 

} 

Я хочу для отображения нет находки, когда нет если ListView элемента в списке, или мы должны показывать в покупать право y text в listview, я попытался, но когда элемент добавлен, а затем Noitem обнаружил, что текст отображается, пока я должен скрыть это. пожалуйста, помогите

ответ

0

U можно использовать setEmptyView() проверить пустоту ListView.

Here вы можете найти хороший пример setEmptyView().

+0

Unalble to hide Emptey text при добавлении нового предмета – Edge

+0

http://wiresareobsolete.com/2010/08/adapting-to-empty-views/ Я попробовал этот код – Edge

0

Положите одно условие в свой метод onCreate после сбора значений для уведомления об авариаторе и после установки адаптера.

if(notifies.size<=0){ 
    emptyText.setVisibility(View.VISIBLE); 
    listView.setAdapter(null); 
    listView.setVisibility(View.GONE); 
} 
+0

Хорошо, подождите, дайте мне проверить – Edge

+0

Невозможно отобразить текст, когда нет ни одного пункта, пожалуйста, мой файл XML я puted вид – Edge

+0

текста там и есть решение пу – Edge

0
if (notifies ==0){ 
// write your code or textview visible and listview gone 

listView .setEmptyView(findViewById(R.id. empty)); 

Toast.makeText(getApplicationContext(),"No items found",3000).show(); 


} 
0

ли как этот

if(notifyList.size()==0){ 
    //tview.setText("Empty"); 
    urLst.setEmptyView(tview); 
    } 
    else{ 
    urAdapter=new Adapter();//create here 
    urList.setAdapter(urAdapter); 
    usAdapter.notifyDataSetChanged(); 
    } 

Надеется, что это помогает. Я сделал этот путь

Update:

Если вы используете AsyncTask принести ListItems затем сделать это в onPostExecute(). Также создайте ссылку Listview.

+0

if (notifications.size() == 0) \t \t { \t \t TextView emptyText = (TextView) findViewById (android.R.id.empty); \t \t listView.setEmptyView (emptyText); \t \t} \t \t \t \t еще \t \t { \t \t \t listView.setAdapter (адаптер); \t \t} попробовал этот код все тот же вопрос, я не могу скрыть – Edge

+0

http://snag.gy/AFmB9.jpg см. Это у меня есть элемент, но не спрятать пустой текст – Edge

Смежные вопросы