Search code examples
androidsqliteandroid-studioandroid-search

Search in Android depends on value of spinner


I created an app that shows a list of places and i created a search dialog wherein the user will type in edittext so he/she will find the desired place. First, search is working when its only place and I try to add spinner with values which are the region of the places and I got problem on the line which i will post below.

GetSearchPlace = dbhelper.getPlaceSearch(placeLocationEditText.getText().toString(),dbhelper.getPlaceSearch(placeRegion.getSelectedItem().toString()));

It says getPlaceSearch (String, string) in DatabaseHelper cannot be applied to (String)

This is my database helper

public List<PlaceModel> getPlaceSearch(String location, String region) {
        List<PlaceModel> search = new ArrayList<PlaceModel>();

        String selectQuery = "SELECT * FROM listing_place where province_name like '" + location + "' and region = '"+region+"'";
        SQLiteDatabase db = this.getReadableDatabase();
        Cursor cursor = db.rawQuery(selectQuery, null);

        if (cursor.moveToFirst()) {
            do {
                PlaceModel pm = new PlaceModel();
                pm.setlisting_title(cursor.getString(cursor.getColumnIndex(KEY_PLACE)));
                search.add(pm);
            }
            while (cursor.moveToNext());
        }
        cursor.close();
        return search;
    }

This is my main activity

final Spinner placeRegion = (Spinner) dialog.findViewById(R.id.spinnerregion);
                ArrayAdapter<String> RegionAdapter = new ArrayAdapter<String>(MainActivity.this,R.layout.spinner_layout, db.getAllRegion());
                RegionAdapter.setDropDownViewResource(R.layout.spinner_layout);
                placeRegion.setAdapter(RegionAdapter);
    placeLocationEditText = (EditText)dialog.findViewById(R.id.placelocation);

                    Button button = (Button) dialog.findViewById(R.id.btnplacesearch);

                    button.setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View v) {
                            dialog.dismiss();

                            PlaceListView = findViewById(R.id.placelayout);
                            ViewGroup parent = (ViewGroup) PlaceListView.getParent();
                            parent.removeView(PlaceListView);
                            PlaceSearchView = getLayoutInflater().inflate(R.layout.searchresult_place, parent, false);
                            parent.addView(PlaceSearchView);

                            GetSearchPlace = dbhelper.getPlaceSearch(placeLocationEditText.getText().toString(),dbhelper.getPlaceSearch(placeRegion.getSelectedItem().toString()));
                            lv2 = (ListView) findViewById(R.id.searchplace_list);
                            lv2.setAdapter(new ViewAdapterSearchPlace());

Solution

  • ok replace your code to below..

    GetSearchPlace = dbhelper.getPlaceSearch(placeLocationEditText.getText().toString(),placeRegion.getSelectedItem().toString());