Android Community
Results 1 to 2 of 2

Thread: Question about using hash table with ArrayList and ArrayAdapter

  1. #1
    Join Date
    Feb 2009
    Posts
    19

    Default Question about using hash table with ArrayList and ArrayAdapter


    Hello,

    I have a simple application to read a dictionary text file

    Code:
    File filePath = new File( "/data/app-private", "dictionary.txt");
    ArrayList<String> dictionary = new ArrayList<String>();
    
    BufferedReader input =  new BufferedReader(new FileReader(fileName));
    while( ( fileLine = input.readLine() ) != null )
    {
        dictionary.add(fileLine);
    }
    
    AutoCompleteTextView textView = (AutoCompleteTextView) findViewById(R.id.edit);
    ArrayAdapter<String> adapter = new ArrayAdapter<String>( this,
                        android.R.layout.simple_dropdown_item_1line, 
                        dictionary);
    textView.setAdapter(adapter);
    This works. However it becomes very slow if there are many entries in the dictionary string list.

    Can I speed it up?
    How does the ArrayList<String> internally organise its entries?
    Is there a way to combine it with one of the Hash classes?

    Many thanks,
    Paul

  2. #2
    Join Date
    Dec 2008
    Location
    Virginia
    Posts
    1,365

    Default Re: Question about using hash table with ArrayList and ArrayAdapter


    The ArrayList is literally named as it is -- it's an ever expanding array-based list of items. You would have to use a different adapter (not an ArrayAdapter, you might have to make your own or see if there's another option in the SDK), but you could use a HashMap to generate the list. You'd take the performance hit on load, but the reading of the values would be far faster.

    The problem though, is the UI thread might struggle with creating a bunch of elements to meet your needs depending on how many items you have.

    You might also want to use a SQL Lite DB for storage, since IO calls are far more expensive than any other task.

Similar Threads

  1. database path after creating a database or table.
    By sangram in forum Developers Guild
    Replies: 3
    Last Post: 05-30-2008, 03:47 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •