Reputation: 71
I need to know if i can search results of search. For example if I have listview with items(Banana Shake , Banana Ice Cream , Apple Juice , Banana Juice, Apple pie,etc) and i type in my search view BANANA so results are (Banana Shake , Banana Ice Cream , Banana Juice) and than below my previous search there is another search in wihich i type JUICE and it pops out BANANA JUICE. I hope you understood me and i hope someone can answer me on this question quickly . here is what my code looks like. BTW i made 2 search views and when I try to do this The results are (APPLE JUICE , BANANA JUICE) beucase there is no connection between searches . PLEASE HELP.
public class recepies extends Activity {
ListView lv;
SearchView sv;
SearchView sv2;
String[] recepies={"Čili Piletina\n"+ " pileće belo meso \n"+" crvena paprika \n"+" čili papričica \n"+" crveni pasulj \n"+" kukuruzni šećer \n"+" paradajz pelat\n"+" kisela pavlaka\n"+ " biljni začin\n "+ " biber\n "+" ulje ",
"Prženija sa svinjskim butom\n" +" svinjski but\n"+" kiseli krastavčići\n , kisala paprika\n,tucana paprika,biljni začin,biber,origano ulje, so, lovorov list",
"Peketići od integralnih palačinki\n" + "integralno brašno ,voda, soda bikarbona, ulje, kisela pavlaka, krastavac, paradajz, kikiriki",
"Ćufte od mesa i karfiola (hrono recept)\n" + "mleveno meso, karfiol, crni luk, beli luk, peršun, belance, so, biber, kurkuma, ulje, tikvice, sok od paradajza",
"Paprika punjena rižom i piletinom\n" +"paprika babura,belo meso,šargarepa,crni luk,pirinač,paradajz,sok od paradajza,biljnog začina,so,biber, kari,peršun, maslinovo ulje,",
"Piletina u sosu od nara\n" +"belo meso,\n" + "soja sos,\n" + "biber,\n" + "kurkuma,\n" + "luk,\n" + "soka od nara,\n" + "đumbir,\n" + "pirinač,\n" + "čili ili tabasko sos,\n" + "bbq ili roštilj sos,"
};
ArrayAdapter<String> adapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_recepies);
registerClickCallback();
lv=(ListView) findViewById(R.id.listView);
sv=(SearchView) findViewById(R.id.searchView1);
sv2=(SearchView) findViewById(R.id.searchView2);
adapter=new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1,recepies);
lv.setAdapter(adapter);
sv2.setOnQueryTextListener(new OnQueryTextListener() {
@Override
public boolean onQueryTextSubmit(String text) {
// TODO Auto-generated method stub
return false;
}
@Override
public boolean onQueryTextChange(String text) {
adapter.getFilter().filter(text);
return false;
}
});
sv.setOnQueryTextListener(new OnQueryTextListener() {
@Override
public boolean onQueryTextSubmit(String text) {
// TODO Auto-generated method stub
return false;
}
@Override
public boolean onQueryTextChange(String text) {
adapter.getFilter().filter(text);
return false;
}
});
}
private void registerClickCallback(){
lv=(ListView) findViewById(R.id.listView);
lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View viewClicked, int position, long id) {
TextView textView= (TextView) viewClicked;
if(position==0){
goToRecepie1();
}else if(position==1){
goToRecepie2();
}else if(position==2){
goToRecepie3();
}else if(position==3){
goToRecepie4();
}else if(position==4){
goToRecepie5();
}else if(position==5){
goToRecepie6();
}
}
});
}
private void goToRecepie6() {
Intent intent = new Intent(this, Recepie6.class);
startActivity(intent);
}
private void goToRecepie5() {
Intent intent = new Intent(this, Recepie5.class);
startActivity(intent);
}
private void goToRecepie4() {
Intent intent = new Intent(this, Recepie4.class);
startActivity(intent);
}
private void goToRecepie3() {
Intent intent = new Intent(this, Recepie3.class);
startActivity(intent);
}
private void goToRecepie2() {
Intent intent = new Intent(this, Recepie2.class);
startActivity(intent);
}
private void goToRecepie1() {
Intent intent = new Intent(this, Recepie1.class);
startActivity(intent);
}
}
Upvotes: 1
Views: 99
Reputation: 506
This is an example without using XML.
List<String> menu = new ArrayList<String>();
List<String> filtered = new ArrayList<String>();
String found;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
menu.add("APPLE JUICE");
menu.add("BANANA JUICE");
menu.add("MANGO JUICE");
menu.add("BANANA SMOOTHIE");
menu.add("PINEAPPLE JUICE");
menu.add("APPLE CIDER");
menu.add("BANANA MILKSHAKE");
for (int i =0;i < menu.size();i++)
{
if (menu.get(i).contains("BANANA"))
{
filtered.add(menu.get(i));
Log.i("AppInfo","1st Filter Round: "+menu.get(i));
}
}
for (int j = 0; j < filtered.size(); j++)
{
if (filtered.get(j).contains("JUICE"))
{
found = filtered.get(j);
Log.i("AppInfo","Final Found: "+found);
}
}
}
just replace the if statement strings within the for loops, with the Strings the user inputs. I hope this helps
Upvotes: 2
Reputation: 52
Make a for each scanning every element in the list you want scanned. If you use an array, you can just check if the nth element contains the word you are searching
Edit: had to take out the "is"
Upvotes: 2