Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: Unable to sort words in dictionary app

  1. #1
    Junior Member
    Join Date
    Jan 2018
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Unable to sort words in dictionary app

    I have a dictionary app. It has the ability to add, favorite and delete words.

    I have the sort button on my menu to sort the words (descending in this case) but but when I click on it, nothing changes.



    Why is this so?

    P.S I want to be able to sort the words in both ascending and descending order


    My project is here: https://drive.google.com/open?id=1zS...W5s0XBpVto8Mg4

  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Unable to sort words in dictionary app

    Please post the code here that you have questions about.
    Be sure to wrap the code in code tags.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Super Moderator pbrockway2's Avatar
    Join Date
    Jan 2012
    Posts
    987
    Thanks
    6
    Thanked 206 Times in 182 Posts

    Default Re: Unable to sort words in dictionary app

    It can be very difficult (for you and for us!) to diagnose a problem when confronted with a mountain of code.

    The tried and true way of dealing with this is to construct a small simple example of the code. Basically create a whole new application designed to illustrate the problem. This is never fun, but it can be very productive. I know from my own experience that, as often as not, I solve a problem in the course of constructing such an example. Remove the clutter, and the problem becomes more visible.

    When dealing with something like an Android project there is a limit to what you can do, but aim for a single Activity app without fragments/splash screens/etc and a very minimal number of widgets (which can be added in code rather using .xml). The Activity should put a few entries into the database and offer to sort them.

    ---

    One thing I noticed was that when "Sort" is selected from the menu you have:

    } else if (item.getItemId() == R.id.sort) {
     
        myDataSource.open();
        myDataSource.sortWords();
        myDataSource.close();
        //finish();
     
    }

    Unless I am missing something (quite possible) calling myDataSource.sortWords() returns you a Cursor. But you aren't doing anything with this cursor.

    In ListFragment's onCreateView() you say

    cursor = mDataSource.selectAllWords();

    and proceed to populate an ArrayList based on that Cursor which does not have any sorting.

    Maybe I'm missing something, but when the user asks for sorted data, shouldn't the fragment recalculate the ArrayList based on a "sorting" cursor? Simply calling sortWords() returns you a Cursor but it makes no change to the order of the data in the database.
    Last edited by pbrockway2; January 24th, 2018 at 12:59 AM. Reason: double post

Similar Threads

  1. [SOLVED] trying sort by second letter of the words input
    By gcabada in forum What's Wrong With My Code?
    Replies: 0
    Last Post: October 3rd, 2014, 10:21 PM
  2. unable to add my array(Words[]) to PriorityQueue
    By Harini Rao in forum What's Wrong With My Code?
    Replies: 5
    Last Post: January 10th, 2012, 07:08 AM
  3. need details on Implementing Dictionary Filters for English words
    By madcrazyboys in forum Java Theory & Questions
    Replies: 2
    Last Post: May 6th, 2011, 12:53 PM
  4. [SOLVED] implementing a dictionary of words using an array of linked lists
    By McTown in forum Java Theory & Questions
    Replies: 3
    Last Post: April 27th, 2011, 02:19 PM
  5. Unable to launch app of java application
    By sharmaneelam in forum What's Wrong With My Code?
    Replies: 1
    Last Post: May 19th, 2010, 08:42 AM