I should do so that, by having a list of names in a gridview, from a search bar I can:
- Make a real-time-search (like google search for instance)
- to remove the names that do not begin with the letters you type (for example if you type 'ja' or 'Ja' or 'JA' the app deletes all the names in the list except 'Jack)
I don't know where to start.. Can you help me?
Here's People.java:
package com.ec.people;
import android.app.Activity;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.EditText;
import android.widget.GridView;
import android.widget.TextView;
import android.widget.Toast;
public class people extends Activity {
GridView peoplelist;
EditText search;
static final String[] numbers = new String[] {
"Rossi", "Loggia", "Boni",
"Milanesi", "Mancini", "Cremonesi",
"Dali - Colombo", "Fiorentini",
"Trevisani", "Monaldo", "Udinesi - Pagnotto",
"Beneventi", "Zucchi", "Calabri",};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.fragment_people);
search = (EditText)findViewById(R.id.editText1);
peoplelist = (GridView)findViewById(R.id.gridView1);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, numbers);
peoplelist.setAdapter(adapter);
peoplelist.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
Toast.makeText(getApplicationContext(),
((TextView) v) .getText(), Toast.LENGTH_SHORT) .show();
}
});
// I use this to perform search
search.addTextChangedListener(new TextWatcher() {
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
for(int i=0; i < numbers.length ; i++)
{
if(numbers[1].startsWith(s.toString()) )
{
}
}
//PerformSearch mysearch = new PerformSearch();
}
@Override
public void afterTextChanged(Editable s) { }
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {}
});
}
}