listView dynamic add item

前端 未结 4 1090
攒了一身酷
攒了一身酷 2020-11-28 12:46

I used ListView to dynamic add item,but there is a problem about not Smooth add. there are textView and button in my listActivity,Iwant to Press button ,then

4条回答
  •  醉酒成梦
    2020-11-28 13:17

    Is your getBtnClickListener method part of the ListActivity or ArrayAdapter class?

    For me, when I update from the ListActivity class, I use this code...

    // code to add a Contact to my database
    // code to add a Contact to the list that
    //   that is used by the ListView
    setListAdapter(adapter);
    getListView().setTextFilterEnabled(true);
    

    When I am updating from a method inside the ArrayAdapter class, I use this code...

     // from a LongPress on a ListView item
     convertView.setOnLongClickListener(new OnLongClickListener(){
         @Override
         public boolean onLongClick(View view) {
             view.performHapticFeedback(0, View.HAPTIC_FEEDBACK_ENABLED);
             // code to remove a Contact name from my database
             // code to remove that Contact name from my list
             //    that is used by the ListView
             ContactsAdapter.this.notifyDataSetChanged();
             return true;
         });
    

提交回复
热议问题