2015-08-02 3 views
0
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) { 

      } 
     }); } 

ответ

0

Если вы хотите обновить listview затем присвоить adapter к нему снова с новыми данными

+0

вы также можете увидеть ссылку, чтобы узнать, как обновить ListView по-разному https://www.youtube.com/watch ? v = hJQmvRHF5xg –

+0

Спасибо, но это не сработало. Как это сделать? –

+0

, где вы хотите обновить свой список, чтобы установить мой код в нужном месте –

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