android - Searching ArrayList with user input -
right now, getting list of questions website , putting inside arraylist<string>
.
now, how take users input, converted string (ssearchvalue), , check arraylist
see if matches? , if finds question contains users search, displays it?
package com.malthorn.anyquestion; import java.io.ioexception; import java.util.arraylist; import java.util.list; import android.os.bundle; import android.app.activity; import android.view.menu; import android.view.view; import android.widget.edittext; import org.jsoup.jsoup; import org.jsoup.nodes.document; import org.jsoup.nodes.element; import org.jsoup.select.elements; import com.malthorn.gasculator.r; public class mainactivity extends activity { @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); document doc; arraylist<string> urls = new arraylist<string>(); edittext isearchvalue = (edittext) findviewbyid(r.id.iquestion); string ssearchvalue = isearchvalue.gettext().tostring(); try { doc = jsoup.connect("http://www.reddit.com/r/askscience/search?q=flair%3a%27psych%27&sort=top&restrict_sr=on").get(); elements links = doc.select("a[href]"); (element link : links) { string href1=link.attr("href"); // if(href1.startswith("http://www.reddit.com/r/askscience/")) { urls.add(link.attr("href")); } system.out.println("\nlink : " + link.attr("href")); } } catch (ioexception e) { e.printstacktrace(); } } @override public boolean oncreateoptionsmenu(menu menu) { // inflate menu; adds items action bar if present. getmenuinflater().inflate(r.menu.main, menu); return true; } }
public string getquestion(string[] questions, string ssearchvalue){ for(string question : questions){ if(question.equals(ssearchvalue)) return question; } return ""; }
this code searches exact matches, if need find questions ressemble search word adivse on googling method substring type string , uses of regex on pattern matching.
Comments
Post a Comment