vendredi 16 octobre 2015

Autocompletetextview simplecursoradapter sqlite class sql query as parameter

I have created custom autocompletetextview component.In that I have also created a populateList method for autocompletetext data.There are several parameters/arguments in method populateList.

Everything is working fine, But

I have problem with 2nd parameters that is of sql query. If I run

final com.example.admin.ctronhot.autocomleteclass aa=(com.example.admin.ctronhot.autocomleteclass)findViewById(R.id.abc);
    final String sql="select * from g101 where desc LIKE '%" + aa.getText().toString() + "%'";
    final String[] mfieldsa=new String[]{"desc"};
    final int[] mobjectsa=new int[]{R.id.desc};
    aa.populateList(R.layout.brow_g101_layout, sql, "desc", aa, mfieldsa, mobjectsa, order.this);

It is showing drop down list But it is not searching in results.

But, If I make changes in autocomplete custom components means, Suppose I fix methods 2nd parameter sql query Directly in that method then it is working fine.

Here is my method, In this way it is working.

    public void populateList(Integer _layoutfile, final String sqlaa, String mfieldget, com.example.admin.ctronhot.autocomleteclass mauto,
                         String[] mfields, int[] mobjects, Context mcontext) {
    SQLiteDatabase db = SQLiteDatabase.openOrCreateDatabase(co.mcurd_data_path_, null);
    Cursor cursor = db.rawQuery("select * from g101 where desc LIKE '%" + mauto.getText().toString() + "%'", null);
    int layoutResourceId = 0;
    final SimpleCursorAdapter adapter = new SimpeCursorAdapter(
            mcontext,        // Context
            _layoutfile,    // Row layout template
            cursor,                    // cursor (set of DB records to map)
            mfields,        // DB Column names
            mobjects                // View IDs to put information in
            , layoutResourceId
    );
    adapter.setCursorToStringConverter(new SimpleCursorAdapter.CursorToStringConverter() {
        @Override
        public CharSequence convertToString(Cursor cursor) {
            final int colIndex = cursor.getColumnIndexOrThrow("desc");
            return cursor.getString(colIndex);
        }
    });

    adapter.setFilterQueryProvider(new FilterQueryProvider() {
        @Override
        public Cursor runQuery(CharSequence description) {
            SQLiteDatabase db = SQLiteDatabase.openOrCreateDatabase(co.mcurd_data_path_, null);
            Cursor managedCursor = db.rawQuery("select * from g101 where desc LIKE '%" + mauto.getText().toString() + "%'", null);

            return managedCursor;
        }
    });
    mauto.setThreshold(1);
    mauto.setAdapter(adapter);
}
enter code here

Please help Me. Thanks in advance.

Aucun commentaire:

Enregistrer un commentaire