Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8074331
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T14:37:02+00:00 2026-06-05T14:37:02+00:00

Please i really need help with listview filter.because I’ve seen many tutorials but it

  • 0

Please i really need help with listview filter.because I’ve seen many tutorials but it doesn’t work.and i really tired of this
just i need the EdiText filter

my project contain four classes:

1-LocationActivity (l’activity prencipale)

public class LocationActivity extends Activity implements LocationListener{

    public final static String LOCATION_ID = "location_id";

    private long location_id;
    private EditText name;
    private EditText comment;

    private RatingBar ratevalue;

    private EditText latitude;
    private EditText longitude;
    private TextView current_latitude;
    private TextView current_longitude;
    private TextView current_source;
    private TextView current_accuracy;
    private LocationDatabase db;
    private BestLocationProxy best_location_proxy;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        db = new LocationDatabase(this);
        best_location_proxy = new BestLocationProxy(this);

        if (savedInstanceState != null) {
            location_id = savedInstanceState.getLong(LOCATION_ID);
        }

        Intent intent = getIntent();
        location_id = intent.getLongExtra(LOCATION_ID, -1);

        setContentView(R.layout.location);
        name = (EditText) findViewById(R.id.name);

        comment = (EditText) findViewById(R.id.comment);
        ratevalue = (RatingBar) findViewById(R.id.ratingbar);
        latitude = (EditText) findViewById(R.id.latitude);
        longitude = (EditText) findViewById(R.id.longitude);
        current_latitude = (TextView) findViewById(R.id.current_latitude);
        current_longitude = (TextView) findViewById(R.id.current_longitude);
        current_source = (TextView) findViewById(R.id.current_source);
        current_accuracy = (TextView) findViewById(R.id.current_accuracy);

        updateLocation(best_location_proxy.getLastKnownLocation());

        Button set_location = (Button) findViewById(R.id.set_location);

        set_location.setOnClickListener(new OnClickListener(){

            public void onClick(View arg0) {
                Location l = best_location_proxy.getLastKnownLocation();
                if (l == null) {
                    return;
                }
                latitude.setText(Double.toString(l.getLatitude()));
                longitude.setText(Double.toString(l.getLongitude()));
            }
        });

        Button closeButton = (Button) findViewById(R.id.close_location_window);
        closeButton.setOnClickListener(new OnClickListener() {

            public void onClick(View v) {
                finish();
            }
        });

        if (location_id != -1) {
            Cursor c = db.getLocation(location_id);
            if (c.getCount() != 1) {
                finish();
                return;
            }
            c.moveToFirst();
            int name_id = c.getColumnIndex(LocationDatabase.FIELD_LOCATIONS_NAME);
            int comment_id = c.getColumnIndex(LocationDatabase.FIELD_LOCATIONS_COMM);
            int ratevalue_id = c.getColumnIndex(LocationDatabase.FIELD_LOCATIONS_RATE);
            int latitude_id = c.getColumnIndex(LocationDatabase.FIELD_LOCATIONS_LATITUDE);
            int longitude_id = c.getColumnIndex(LocationDatabase.FIELD_LOCATIONS_LONGITUDE);

            name.setText(c.getString(name_id));

            comment.setText(c.getString(comment_id));
            ratevalue.setRating(c.getLong(ratevalue_id));
            latitude.setText(Double.toString(c.getDouble(latitude_id)));
            longitude.setText(Double.toString(c.getDouble(longitude_id)));
            c.close();
        }

    }


    @Override
    protected void onResume() {
        super.onResume();
        best_location_proxy.requestLocationUpdates(100000, 0, this);
    }


    @Override
    protected void onPause() {
        super.onPause();
        best_location_proxy.removeUpdates(this);

        String s_name = name.getText().toString();
        if (s_name.equals("")) {
            return;
        }

        String s_comment = comment.getText().toString();
        if (s_comment.equals("")) {
            return;
        }
        Double d_ratevalue = (double) ratevalue.getRating();

        Double d_latitude = null;
        String s_latitude = latitude.getText().toString();
        if (!s_latitude.equals("")) {
            d_latitude = Double.parseDouble(s_latitude);
        }

        Double d_longitude = null;
        String s_longitude = longitude.getText().toString();
        if (!s_longitude.equals("")) {
            d_longitude = Double.parseDouble(s_longitude);
        }

        if (location_id != -1) {
            db.updateLocation(location_id, s_name,  s_comment, d_ratevalue, d_latitude, d_longitude);
        } else {

            location_id = db.createLocation(s_name, s_comment, d_ratevalue, d_latitude, d_longitude);
        }
    }


    @Override
    protected void onSaveInstanceState(Bundle outState) {
        super.onSaveInstanceState(outState);
        outState.putLong(LOCATION_ID, location_id);
    }

    private void updateLocation(Location l){

        if (l == null){
            current_source.setText(R.string.no_provider);
            current_latitude.setText(R.string.unavailable);
            current_longitude.setText(R.string.unavailable);
            current_accuracy.setText(R.string.unavailable);
            return;
        }

        String source;
        if (l.getProvider().equals(LocationManager.GPS_PROVIDER)){
            source = getString(R.string.location_map);
        } else if (l.getProvider().equals(LocationManager.NETWORK_PROVIDER)){
            source = getString(R.string.cell);
        } else {
            source = getString(R.string.unknown);
        }

        current_source.setText(source);
        current_latitude.setText(Double.toString(l.getLatitude()));
        current_longitude.setText(Double.toString(l.getLongitude()));
        current_accuracy.setText(Float.toString(l.getAccuracy()));
    }


    public void onLocationChanged(Location location) {
        updateLocation(location);
    }


    public void onProviderDisabled(String provider) {
    }


    public void onProviderEnabled(String provider) {    
    }


    public void onStatusChanged(String provider, int status, Bundle extras) {
    }

}

2-LocationListActivity (listview activity)

public class LocationListActivity extends ListActivity {

    private Cursor locations;
    private LocationDatabase db;

    private final static String RADAR_ACTION = "com.google.android.radar.SHOW_RADAR";


    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);


        db = new LocationDatabase(this);

        setContentView(R.layout.list);
        registerForContextMenu(this.getListView());
        getListView().setOnItemClickListener(new OnItemClickListener() {

            public void onItemClick(AdapterView<?> parent, View view,
                    int position, long id) {
                Cursor c = (Cursor) parent.getAdapter().getItem(position);

                int name_id = c.getColumnIndex(LocationDatabase.FIELD_LOCATIONS_NAME);
                int latitude_id = c
                        .getColumnIndex(LocationDatabase.FIELD_LOCATIONS_LATITUDE);
                int longitude_id = c
                        .getColumnIndex(LocationDatabase.FIELD_LOCATIONS_LONGITUDE);
                String name = c.getString(name_id);
                float latitude = c.getFloat(latitude_id);
                float longitude = c.getFloat(longitude_id);

                startBest(latitude, longitude, name);
            }
        });
    }


    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        super.onCreateOptionsMenu(menu);

        MenuItem add = menu.add(R.string.location_add);
        add.setIcon(android.R.drawable.ic_menu_add);
        add.setOnMenuItemClickListener(new OnMenuItemClickListener() {

            public boolean onMenuItemClick(MenuItem item) {
                Intent i = new Intent();
                i.setClass(LocationListActivity.this, LocationActivity.class);
                startActivity(i);
                return true;
            }
        });

        return true;
    }


    @Override
    protected void onResume() {
        super.onResume();
        updateList();
    }


    @Override
    protected void onStop() {
        super.onStop();
        if (locations != null){
            locations.close();
        }
    }


    @Override
    public void onCreateContextMenu(ContextMenu menu, View v,
            ContextMenuInfo menuInfo) {
        super.onCreateContextMenu(menu, v, menuInfo);
        AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) menuInfo;
        Cursor c = (Cursor) getListView().getItemAtPosition(info.position);

        int id_id = c.getColumnIndex(LocationDatabase.FIELD_LOCATIONS_ID);
        int name_id = c.getColumnIndex(LocationDatabase.FIELD_LOCATIONS_NAME);
        int latitude_id = c.getColumnIndex(LocationDatabase.FIELD_LOCATIONS_LATITUDE);
        int longitude_id = c.getColumnIndex(LocationDatabase.FIELD_LOCATIONS_LONGITUDE);

        final long id = c.getLong(id_id);
        final String name = c.getString(name_id);
        final float latitude = c.getFloat(latitude_id);
        final float longitude = c.getFloat(longitude_id);

        menu.setHeaderTitle(name);

        MenuItem map = menu.add(R.string.location_map);
        map.setOnMenuItemClickListener(new OnMenuItemClickListener() {

            public boolean onMenuItemClick(MenuItem item) {
                startMap(latitude, longitude, name);
                return true;
            }
        });

        MenuItem edit = menu.add(R.string.location_edit);
        edit.setOnMenuItemClickListener(new OnMenuItemClickListener() {

            public boolean onMenuItemClick(MenuItem item) {
                Intent i = new Intent();
                i.setClass(LocationListActivity.this, LocationActivity.class);
                i.putExtra(LocationActivity.LOCATION_ID, id);
                startActivity(i);
                return true;
            }
        });

        MenuItem delete = menu.add(R.string.location_delete);
        delete.setOnMenuItemClickListener(new OnMenuItemClickListener() {

            public boolean onMenuItemClick(MenuItem item) {
                db.deleteLocation(id);
                updateList();
                return true;
            }
        });
    }

    private void updateList() {

        if (locations != null) {
            locations.close();
        }

        locations = db.getAllLocations();
        ListAdapter adapter = new SimpleCursorAdapter(this,
                android.R.layout.simple_list_item_1, locations,
                new String[] { LocationDatabase.FIELD_LOCATIONS_NAME, },
                new int[] { android.R.id.text1 });
        setListAdapter(adapter);
    }

    private void startRadar(float latitude, float longitude){
        Intent i = new Intent(RADAR_ACTION);
        i.putExtra("latitude", latitude);
        i.putExtra("longitude", longitude);
        startActivity(i);
    }

    private void startMap(float latitude, float longitude, String name){
        Formatter f = new Formatter(Locale.US);
        f.format("geo:0,0?q=%1$.5f,%2$.5f(%3$s)", latitude, longitude, name);
        Uri uri = Uri.parse(f.toString());
        Intent i = new Intent(Intent.ACTION_VIEW, uri);
        startActivity(i);
    }

    private void startBest(float latitude, float longitude, String name){
        if (isRadarAvailable()){
            startRadar(latitude, longitude);
        } else {
            startMap(latitude, longitude, name);
        }
    }

    private boolean isRadarAvailable(){
        return isIntentAvailable(RADAR_ACTION);
    }

    private boolean isIntentAvailable(String action) {
        PackageManager packageManager = getPackageManager();
        final Intent intent = new Intent(action);
        @SuppressWarnings("rawtypes")
        List list =
                packageManager.queryIntentActivities(intent,
                        PackageManager.MATCH_DEFAULT_ONLY);
        return list.size() > 0;
    }
}

3-LocationDataase (database activity sqlite)

public class LocationDatabase extends SQLiteOpenHelper {

    public final static String TAG = LocationDatabase.class.toString();

    public final static String DB_NAME = "locations";
    public final static int DB_VERSION = 1;

    public final static String TABLE_LOCATIONS = "locations";

    public final static String FIELD_LOCATIONS_ID = "_id";
    public final static String FIELD_LOCATIONS_NAME = "name";
    public final static String FIELD_LOCATIONS_COMM = "comment";
    public final static String FIELD_LOCATIONS_RATE = "ratevalue";
    public final static String FIELD_LOCATIONS_LATITUDE = "latitude";
    public final static String FIELD_LOCATIONS_LONGITUDE = "longitude";

    public final static String[] PROJECTION_LOCATIONS = { FIELD_LOCATIONS_ID,
            FIELD_LOCATIONS_NAME, FIELD_LOCATIONS_COMM, FIELD_LOCATIONS_RATE, FIELD_LOCATIONS_LATITUDE,
            FIELD_LOCATIONS_LONGITUDE };

    public LocationDatabase(Context context) {
        super(context, DB_NAME, null, DB_VERSION);
        getWritableDatabase(); // make upgrades work
    }

    @Override
    public void onCreate(SQLiteDatabase db) {
        db.execSQL("CREATE TABLE " + TABLE_LOCATIONS + " ( " + 
                FIELD_LOCATIONS_ID + " INTEGER PRIMARY KEY NOT NULL, " + 
                FIELD_LOCATIONS_NAME + " Text, " +

                FIELD_LOCATIONS_COMM + " Text, " +
                FIELD_LOCATIONS_RATE + " REAL, " +
                FIELD_LOCATIONS_LATITUDE + " REAL, "
                + FIELD_LOCATIONS_LONGITUDE + " REAL )");
    }

    @Override
    public void onUpgrade(SQLiteDatabase arg0, int arg1, int arg2) {
    }

    public long createLocation(String name, String comment, Double ratevalue, Double latitude, Double longitude) {
        Log.d(TAG, "Inserting location " + name + comment + ratevalue);
        SQLiteDatabase db = getWritableDatabase();

        ContentValues values = new ContentValues();
        values.put(FIELD_LOCATIONS_NAME, name);

        values.put(FIELD_LOCATIONS_COMM, comment);
        values.put(FIELD_LOCATIONS_RATE, ratevalue);
        values.put(FIELD_LOCATIONS_LATITUDE, latitude);
        values.put(FIELD_LOCATIONS_LONGITUDE, longitude);

        long id = db.insert(TABLE_LOCATIONS, null, values);
        Log.d(TAG, Long.toString(id));
        db.close();
        return id;
    }

    public void updateLocation(Long location_id, String name, String comment, Double ratevalue, Double latitude,
            Double longitude) {
        Log.d(TAG, "Updating location");
        SQLiteDatabase db = getWritableDatabase();

        ContentValues values = new ContentValues();
        values.put(FIELD_LOCATIONS_NAME, name);

        values.put(FIELD_LOCATIONS_COMM, comment);
        values.put(FIELD_LOCATIONS_RATE, ratevalue);
        values.put(FIELD_LOCATIONS_LATITUDE, latitude);
        values.put(FIELD_LOCATIONS_LONGITUDE, longitude);

        db.update(TABLE_LOCATIONS, values, "_id = ?",
                new String[] { location_id.toString() });
        db.close();
    }

    public Cursor getAllLocations() {
        Log.d(TAG, "Selecting all locations");
        SQLiteDatabase db = getReadableDatabase();
        Cursor c = db.query(TABLE_LOCATIONS, PROJECTION_LOCATIONS, null, null,
                null, null, FIELD_LOCATIONS_NAME);
        Log.d(TAG, Integer.toString(c.getCount()));
        db.close();
        return c;
    }

    public Cursor getLocation(long location_id) {
        Log.d(TAG, "Selecting location " + Long.toString(location_id));
        SQLiteDatabase db = getReadableDatabase();
        Cursor c = db.query(TABLE_LOCATIONS, PROJECTION_LOCATIONS, "_id = ?",
                new String[] { Long.toString(location_id) }, null, null, null);
        Log.d(TAG, Integer.toString(c.getCount()));
        db.close();
        return c;
    }

    public void deleteLocation(long location_id){
        Log.d(TAG, "Deleting location " + Long.toString(location_id));
        SQLiteDatabase db = getWritableDatabase();
        db.delete(TABLE_LOCATIONS, "_id = ?", new String[] {Long.toString(location_id)});
    }
}

4-BestLocationProxy

in the Layout I have location.xml and list.xml

1-location.xml

<?xml version="1.0" encoding="utf-8"?>
<ScrollView
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="311dp"
        android:orientation="vertical"
        android:paddingRight="20dip" >

        <TableLayout
            android:layout_width="fill_parent"
            android:layout_height="wrap_content">

                <TextView
                    android:text="@string/name"
                    android:gravity="left|center_vertical"
                    android:textAppearance="?android:attr/textAppearanceMedium"
                    android:paddingRight="10dip" />
                <EditText
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content"
                    android:editable="true"

                    android:id="@+id/name"
                    android:singleLine="true"
                    android:layout_weight="1" />


                                <TextView
                    android:text="@string/comment"
                    android:gravity="left|center_vertical"
                    android:textAppearance="?android:attr/textAppearanceMedium"
                    android:paddingRight="10dip" />
                <EditText
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content"
                    android:editable="true"

                    android:id="@+id/comment"
                    android:singleLine="true"
                    android:layout_weight="1" />

                <TextView
                    android:text="@string/Rate"
                    android:gravity="left|center_vertical"
                    android:textAppearance="?android:attr/textAppearanceMedium"
                    android:paddingRight="10dip" />
</TableLayout>

                <RatingBar
                    android:id="@+id/ratingbar"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content" 
                    android:stepSize="1"
                    />

            <TableLayout
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                >
                <TextView
                    android:text="@string/latitude"
                    android:gravity="left|center_vertical"
                    android:textAppearance="?android:attr/textAppearanceMedium"
                    android:paddingRight="10dip" />
                <EditText
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content"
                    android:editable="true"

                    android:id="@+id/latitude"
                    android:singleLine="true"
                    android:layout_weight="1"
                    android:numeric="signed|decimal" />


                <TextView
                    android:text="@string/longitude"
                    android:gravity="left|center_vertical"
                    android:textAppearance="?android:attr/textAppearanceMedium"
                    android:paddingRight="10dip" />
                <EditText
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content"
                    android:editable="true"

                    android:id="@+id/longitude"
                    android:singleLine="true"
                    android:layout_weight="1"
                    android:numeric="signed|decimal" />

        </TableLayout>
        <TableLayout
            android:layout_width="fill_parent"
            android:layout_height="wrap_content">
        <TableRow>
        <TextView 
            android:text="@string/source" 
            android:gravity="right|center_vertical" 
            android:textAppearance="?android:attr/textAppearanceMedium" 
            android:paddingRight="10dip" /> 
        <TextView android:layout_width="fill_parent" 
            android:layout_height="wrap_content" 
            android:id="@+id/current_source" 
            android:layout_weight="1" 
            android:textAppearance="?android:attr/textAppearanceSmall" /> 
  </TableRow>


            <TableRow>
                <TextView
                    android:text="@string/latitude"
                    android:gravity="right|center_vertical"
                    android:textAppearance="?android:attr/textAppearanceMedium"
                    android:paddingRight="10dip" />
                <TextView
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content"
                    android:id="@+id/current_latitude"
                    android:layout_weight="1"
                    android:textAppearance="?android:attr/textAppearanceSmall" />
            </TableRow>
            <TableRow>
                <TextView
                    android:text="@string/longitude"
                    android:gravity="right|center_vertical"
                    android:textAppearance="?android:attr/textAppearanceMedium"
                    android:paddingRight="10dip" />
                <TextView
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content"
                    android:id="@+id/current_longitude"
                    android:layout_weight="1"
                    android:textAppearance="?android:attr/textAppearanceSmall" />
            </TableRow>
            <TableRow>
                <TextView
                    android:text="@string/accuracy"
                    android:gravity="right|center_vertical"
                    android:textAppearance="?android:attr/textAppearanceMedium"
                    android:paddingRight="10dip" />
                <TextView
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content"
                    android:id="@+id/current_accuracy"
                    android:layout_weight="1"
                    android:textAppearance="?android:attr/textAppearanceSmall" />
            </TableRow>
        </TableLayout>

        <View
            android:layout_width="fill_parent"
            android:background="@android:drawable/divider_horizontal_bright"
            android:layout_marginBottom="10dip"
            android:layout_marginTop="10dip"
            android:layout_height="4dip" />

        <Button
            android:id="@+id/set_location"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="@string/set_location" />

        <Button
            android:id="@+id/close_location_window"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="@string/close" />

    </LinearLayout>
</ScrollView>

2- list.xml

<?xml version="1.0" encoding="utf-8"?>


<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical">
    <ListView
        android:id="@android:id/list"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:longClickable="true"
        android:layout_weight="1" />
    <ScrollView
        android:id="@android:id/empty"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:fillViewport="true">
        <TextView
            android:id="@+id/emptyText"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="@string/empty_msg"
            android:textSize="20sp"
            android:textColor="?android:attr/textColorSecondary"
            android:paddingLeft="10dip"
            android:paddingRight="10dip"
            android:paddingTop="10dip"
            android:lineSpacingMultiplier="0.92" />
    </ScrollView>
</LinearLayout>

Sorry…too Long

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T14:37:03+00:00Added an answer on June 5, 2026 at 2:37 pm

    I think I see what you are trying to do. Here is an example using the ListView’s TextFilter:

    public class Example extends Activity {
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
    
            LinearLayout layout = new LinearLayout(this);
            ListView list = new ListView(this);
            layout.addView(list);
            setContentView(layout);
    
            String[] array = {"one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten"};
            ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, array);
            list.setAdapter(adapter);
            list.setTextFilterEnabled(true);
        }
    }
    

    You need to open the keyboard by long pressing the Menu button.

    Unfortunately, this feature is completely inadequate to sort a result set from a CursorAdapter. In fact the TextFilter doesn’t even respond when I bound it to a SimpleCursorAdapter.

    Solution:

    Here’s one basic approach, try adding an EditText and a Button. Say, you want to sort the location by name. When the user clicks the button you query your database with what’s in the EditText, like this:

    db.query(TABLE_LOCATIONS, PROJECTION_LOCATIONS, 
                FIELD_LOCATIONS_NAME " LIKE '%?%'", editTextString,
                null, null, FIELD_LOCATIONS_NAME);
    

    Of course, editTextString is the user’s input from the EditText. Now simply set this new Cursor returned from your Database to your adapter like this:

    adapter.changeCursor(newCursor);
    

    You will have to use the same approach to sort by more than just the name, but this is the general idea. Design wise you can move the search EditText and Button into a PopUpWindow, or instead of a Button your can re-query the Database with every new letter typed into the EditText with a TextWatcher; there are many different methods. Hope that helps.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am still a noob so i really need help please.Is it possible to
Can somebody help me? please i really need to parse at least google. i
rowanparker https://github.com/rowanparker/kohana-3-paypal I really need this module but I can not use it because
i really need some help on this. I searched the internet but couldn't find
I'm pants at MySQL, so I really need some help with this, please: I
I really need your help. I tried everything but the result is always the
Please excuse me if this question is really obvious but i've tried everything. I
Please help me understand this. I created a really simple program to try to
This is not really a programming question but please bear with me as I
This is not a really Programming Question, but please bear with me as it's

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.