如何更新列表视图?

时间:2015-08-02 09:35:50

标签: listview

public class ActivityListview extends Activity {

   public ArrayAdapter adapter;


   @Override
   protected void onResume() {

       G.curentActivity = this;
       super.onResume();
       if (adapter != null) {
           adapter.notifyDataSetChanged();
       }

   }


   @Override
   public void onCreate(Bundle savedInstanceState) {
       super.onCreate(savedInstanceState);
       setContentView(R.layout.activity_listview);

       ListView lstContent = (ListView) findViewById(R.id.lstContent);
       adapter = new ActivityAdapterNote(G.notes);
       lstContent.setAdapter(adapter);

       G.notes.clear();
       adapter.notifyDataSetChanged();
       G.readOfDB();

       final EditText edtSearch = (EditText) findViewById(R.id.edtSearch);
       edtSearch.addTextChangedListener(new TextWatcher() {

           @Override
           public void onTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) {
               G.notes.clear();

               String input = edtSearch.getText().toString();

               Cursor cursor = G.db.rawQuery("SELECT  * FROM MDS WHERE mds_name LIKE '%" + input + "%'", null);

               while (cursor.moveToNext()) {
                   StructNote item = new StructNote();

                   item.name = cursor.getString(cursor.getColumnIndex("mds_name"));
                   item.some = cursor.getLong(cursor.getColumnIndex("mds_some"));
                   item.vahed = cursor.getString(cursor.getColumnIndex("mds_vahed"));
                   item.priceVahed = cursor.getLong(cursor.getColumnIndex("mds_priceVahed"));
                   item.priceComplete = cursor.getLong(cursor.getColumnIndex("mds_priceComplete"));
                   item.hours = cursor.getInt(cursor.getColumnIndex("mds_hours"));
                   item.month = cursor.getInt(cursor.getColumnIndex("mds_minute"));
                   item.second = cursor.getInt(cursor.getColumnIndex("mds_second"));
                   item.year = cursor.getInt(cursor.getColumnIndex("mds_year"));
                   item.month = cursor.getInt(cursor.getColumnIndex("mds_month"));
                   item.day = cursor.getInt(cursor.getColumnIndex("mds_day"));

                   G.notes.add(item);

               }
               cursor.close();

           }


           @Override
           public void beforeTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) {

           }


           @Override
           public void afterTextChanged(Editable arg0) {

           }
       }); }

1 个答案:

答案 0 :(得分:0)

如果您想更新listview,请使用新数据再次为其adapter