[Mobile app]How to do search function for Mobile app?

soulblader_86

Supremacy Member
Joined
Sep 28, 2007
Messages
9,012
Reaction score
0
his is my current app, I am able to return the String name of different countries

PHP:
  package com.example.autocompletetutorial;
    
    
    
    import android.os.Bundle;
    import android.app.Activity;
    import android.view.Menu;
    import android.widget.ArrayAdapter;
    import android.widget.AutoCompleteTextView;
    
    public class MainActivity extends Activity {
    
    	String[] countries = {"Afghanistan", "Albania", "Algeria", "American Samoa", "Andorra", "Angola", 
    			"Anguilla", "Antarctica", "Antigua and Barbuda", "Argentina", "Armenia", "Aruba", "Australia", 
    			"Austria", "Azerbaijan", "Bahamas", "Bahrain", "Bangladesh", "Barbados", "Belarus", "Belgium", 
    			"Belize", "Benin", "Bermuda", "Bhutan", "Bolivia", "Bosnia and Herzegowina", "Botswana", "Bouvet Island", 
    			"Brazil", "British Indian Ocean Territory", "Brunei Darussalam", "Bulgaria", "Burkina Faso", "Burundi", "Cambodia", 
    			"Cameroon", "Canada", "Cape Verde", "Cayman Islands", "Central African Republic", "Chad", "Chile", "China", 
    			"Christmas Island", "Cocos (Keeling) Islands", "Colombia", "Comoros", "Congo", "Congo, the Democratic Republic of the", 
    			"Cook Islands", "Costa Rica", "Cote d'Ivoire", "Croatia (Hrvatska)", "Cuba", "Cyprus", "Czech Republic", "Denmark", 
    			"Djibouti", "Dominica", "Dominican Republic", "East Timor", "Ecuador", "Egypt", "El Salvador", "Equatorial Guinea", 
    			"Eritrea", "Estonia", "Ethiopia", "Falkland Islands (Malvinas)", "Faroe Islands", "Fiji", "Finland", "France", 
    			"France Metropolitan", "French Guiana", "French Polynesia", "French Southern Territories", 
    			"Gabon", "Gambia", "Georgia", "Germany", "Ghana", "Gibraltar", "Greece", "Greenland", "Grenada", 
    			"Guadeloupe", "Guam", "Guatemala", "Guinea", "Guinea-Bissau", "Guyana", "Haiti", "Heard and Mc Donald Islands", 
    			"Holy See (Vatican City State)", "Honduras", "Hong Kong", "Hungary", "Iceland", "India", "Indonesia", 
    			"Iran (Islamic Republic of)", "Iraq", "Ireland", "Israel", "Italy", "Jamaica", "Japan", "Jordan", 
    			"Kazakhstan", "Kenya", "Kiribati", "Korea, Democratic People's Republic of", "Korea, Republic of", "Kuwait", 
    			"Kyrgyzstan", "Lao, People's Democratic Republic", "Latvia", "Lebanon", "Lesotho", "Liberia", 
    			"Libyan Arab Jamahiriya", "Liechtenstein", "Lithuania", "Luxembourg", "Macau", "Macedonia, The Former Yugoslav Republic of",
    			"Madagascar", "Malawi", "Malaysia", "Maldives", "Mali", "Malta", "Marshall Islands", "Martinique", "Mauritania", 
    			"Mauritius", "Mayotte", "Mexico", "Micronesia, Federated States of", "Moldova, Republic of", "Monaco", "Mongolia", 
    			"Montserrat", "Morocco", "Mozambique", "Myanmar", "Namibia", "Nauru", "Nepal", "Netherlands", "Netherlands Antilles", 
    			"New Caledonia", "New Zealand", "Nicaragua", "Niger", "Nigeria", "Niue", "Norfolk Island", "Northern Mariana Islands", 
    			"Norway", "Oman", "Pakistan", "Palau", "Panama", "Papua New Guinea", "Paraguay", "Peru", "Philippines", 
    			"Pitcairn", "Poland", "Portugal", "Puerto Rico", "Qatar", "Reunion", "Romania", "Russian Federation", "Rwanda", 
    			"Saint Kitts and Nevis", "Saint Lucia", "Saint Vincent and the Grenadines", "Samoa", "San Marino", "Sao Tome and Principe",
    			"Saudi Arabia", "Senegal", "Seychelles", "Sierra Leone", "Singapore", "Slovakia (Slovak Republic)", "Slovenia", 
    			"Solomon Islands", "Somalia", "South Africa", "South Georgia and the South Sandwich Islands", "Spain", "Sri Lanka",
    			"St. Helena", "St. Pierre and Miquelon", "Sudan", "Suriname", "Svalbard and Jan Mayen Islands", "Swaziland", "Sweden", 
    			"Switzerland", "Syrian Arab Republic", "Taiwan, Province of China", "Tajikistan", "Tanzania, United Republic of", "Thailand", 
    			"Togo", "Tokelau", "Tonga", "Trinidad and Tobago", "Tunisia", "Turkey", "Turkmenistan", "Turks and Caicos Islands", "Tuvalu", 
    			"Uganda", "Ukraine", "United Arab Emirates", "United Kingdom", "United States", "United States Minor Outlying Islands", 
    			"Uruguay", "Uzbekistan", "Vanuatu", "Venezuela", "Vietnam", "Virgin Islands (British)", "Virgin Islands (U.S.)",
    			"Wallis and Futuna Islands", "Western Sahara", "Yemen", "Yugoslavia", "Zambia", "Zimbabwe"};
    	
    	
    	@Override
    	protected void onCreate(Bundle savedInstanceState) {
    		super.onCreate(savedInstanceState);
    		setContentView(R.layout.activity_main);
    	      ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
    	    		  android.R.layout.simple_dropdown_item_1line, countries);
    	        AutoCompleteTextView textView = (AutoCompleteTextView)
    	                findViewById(R.id.autocomplete);
    	        textView.setAdapter(adapter);
    	        textView.setThreshold(1);
    		
    		
    		
    		
    	}
    
    	@Override
    	public boolean onCreateOptionsMenu(Menu menu) {
    		// Inflate the menu; this adds items to the action bar if it is present.
    		getMenuInflater().inflate(R.menu.main, menu);
    		return true;
    	}
    
    }

However I need a arraylist base on the following java
PHP:
        public class User 
        {
           // attributes
           private String accountID;
           private String companyName; 
           private String designation; 
           private String firstName; 
           private String lastName; 
           private String profileimageBLOB;
           
           // behaviors
           public User() 	// default constructor
           {
               // attributes will be initialized to their default values
           }
        
           public User(String accID ,String comName, String design, String fName, String lName, String image) // parameterized constructor
           {
        	   accountID = accID;
        	   companyName = comName;
        	   designation = design;
        	   firstName = fName;
        	   lastName = lName;
        	   profileimageBLOB = image;
           }
           
           // set and get methods
           public void   setAccountID(String accID) { accountID = accID; }
           public String    getAccountID() { 
              return accountID; }  
           public void   setCompanyName(String comName) {companyName = comName; }
           public String getCompanyName() { 
              return companyName; }
           public void   setDesignation(String design) { designation = design; }
           public String    getDesignation(){ 
              return designation; }
           public void   setFirstName(String fName) { firstName = fName; }
           public String    getFirstName(){ 
              return firstName; }
           public void   setLastName(String lName) { lastName = lName; }
           public String    getLastName(){ 
              return lastName; }
           public void   setProfileImage(String image) { profileimageBLOB = image; }
           public String    getProfileImage(){ 
              return firstName; }
        
        
           // toString() method
           public String toString()
           {
              return  firstName + "\t" + lastName + "\t" + profileimageBLOB;
           }
           
        
        }

How can I edit the app, to help me display the appear Photo and firstName, last Name from the arraylist, instead of everything?

That is what I intend to do

OSHAd.jpg


uYQUm.png



PHP:
    import java.util.ArrayList;
    import java.util.HashMap;
    import java.util.Iterator;
    
    import android.app.Activity;
    import android.os.Bundle;
    import android.text.Editable;
    import android.text.TextWatcher;
    import android.widget.ArrayAdapter;
    import android.widget.EditText;
    import android.widget.ListView;
     
    public class MainActivity extends Activity {
         
        // List view
        private ListView lv;
         
        // Listview Adapter
        ArrayAdapter<String> adapter;
         
        // Search EditText
        EditText inputSearch;
         
         
        // ArrayList for Listview
        ArrayList userList = new ArrayList();
    
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
             
           
            User p = null;
            
            p = new User("1", "Starhub Pte Ltd","Manager","Jason", "Bourne","");
            userList.add(p);      
            p = new User("2", "Singtel Pte Ltd", "Senior Manager","Ben", "Chia","");
            userList.add(p);  
            p = new User("3", "Ngee Ann Polytechnic", "Senior lecturer","Charles", "Xavier","");
            userList.add(p); 
            p = new User("4", "Dreamcity Pte Ltd", "","Ben", "Chia","");
            userList.add(p); 
            p = new User("5", "DBS Corporation", "Secretary","Michelle", "Chong","");
            userList.add(p); 
            p = new User("6", "OCBC bank", "Deputy finance Manager","YongZheng", "Wong","");
            userList.add(p); 
         
    
            lv = (ListView) findViewById(R.id.list_view);
            inputSearch = (EditText) findViewById(R.id.inputSearch);
    
            // Adding items to listview
            adapter = new ArrayAdapter<String>(this, R.layout.list_item, R.id.name_list, userList);
            lv.setAdapter(adapter);  
            //new line 
            inputSearch.addTextChangedListener(new TextWatcher() {
    
                @Override
                public void onTextChanged(CharSequence cs, int arg1, int arg2, int arg3) {
                    // When user changed the Text
                    MainActivity.this.adapter.getFilter().filter(cs);   
                }
    
                @Override
                public void beforeTextChanged(CharSequence arg0, int arg1, int arg2,
                        int arg3) {
                    // TODO Auto-generated method stub
    
                }
    
                @Override
                public void afterTextChanged(Editable arg0) {
                    // TODO Auto-generated method stub                          
                }
            });
    
        }
    
    }
How can I improve from my mainactivity class? I need to display the photo the left side beside the result of the search.
 
Last edited:

soulblader_86

Supremacy Member
Joined
Sep 28, 2007
Messages
9,012
Reaction score
0
Hi, if I want to use a autocomplete to show my result of from arraylist, when I search by name.

like this, instead of using listview

something like this
autocomplete.png


Is it possible?
 

stupidbodo

Junior Member
Joined
Mar 26, 2010
Messages
89
Reaction score
0
I'm not a mobile app dev guy but I recently came across Algolia | Hosted cloud search as a service, a search as a service provider that returns really fast real-time result mostly under 10milliseconds. It might be helpful because once you reach a certain volume getting these results to return in real time could be tricky.

I'm not sure if it is suitable for your project but if I'm doing it for a real world use case I would definitely try out these guys.

This is not a spam or self promotion and I am not related to them in any way unlike those guys spamming in the "WEB HOSTING COMPANY TO RECOMMEND!" thread -.-"
 
Important Forum Advisory Note
This forum is moderated by volunteer moderators who will react only to members' feedback on posts. Moderators are not employees or representatives of HWZ Forums. Forum members and moderators are responsible for their own posts. Please refer to our Community Guidelines and Standards and Terms and Conditions for more information.
Top