java - When I search listview item and then click desire item, it does open first position of List View -
i have searchable country listview. when click country list item without search, it's works properly. when type brazil in search box , click brazil, open country_details.java activity , pass afganistan details. when type brazil in search box , click brazil, want ot pass brazil details in webview.
full source code : https://drive.google.com/open?id=0b46bpr7lkljpzfrhcv9ddmiwetq
here code.
package com.nasir.search; import java.util.arraylist; import java.util.arrays; import android.app.activity; import android.app.listactivity; import android.content.intent; import android.os.bundle; import android.text.editable; import android.text.textwatcher; import android.view.layoutinflater; import android.view.view; import android.view.viewgroup; import android.widget.adapterview; import android.widget.adapterview.onitemclicklistener; import android.widget.baseadapter; import android.widget.edittext; import android.widget.listview; import android.widget.textview; public class search_country extends listactivity { private edittext searchtext; private listview listtext; private string[] number_list = { "afghanistan", "albania", "algeria", "brazil"}; private arraylist<string> array_sort; int textlength = 0; public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.search_country); searchtext = (edittext) findviewbyid(r.id.listview_search); listtext = (listview) findviewbyid(android.r.id.list); array_sort = new arraylist<string>(arrays.aslist(number_list)); setlistadapter(new bsadapter(this)); searchtext.addtextchangedlistener(new textwatcher() { public void aftertextchanged(editable s) { } public void beforetextchanged(charsequence s, int start, int count, int after) { } public void ontextchanged(charsequence s, int start, int before, int count) { textlength = searchtext.gettext().length(); array_sort.clear(); (int = 0; < number_list.length; i++) { if (textlength <= number_list[i].length()) { if(number_list[i].touppercase().contains(searchtext.gettext().tostring().touppercase().trim())) { array_sort.add(number_list[i]); } } } appendlist(array_sort); } }); listtext.setonitemclicklistener(new onitemclicklistener() { public void onitemclick(adapterview<?> parent, view view, int position, long id) { switch( position ) { case 0: intent intent = new intent(search_country.this, country_details.class); intent.putextra("header", getstring(r.string.html_afganistan)); startactivity(intent); break; case 1: intent intent1 = new intent(search_country.this, country_details.class); intent1.putextra("header", getstring(r.string.html_albenia)); startactivity(intent1); break; case 2: intent intent2 = new intent(search_country.this, country_details.class); intent2.putextra("header", getstring(r.string.html_algeria)); startactivity(intent2); break; case 3: intent intent3 = new intent(search_country.this, country_details.class); intent3.putextra("header", getstring(r.string.html_brazil)); startactivity(intent3); break; } } }); } public void appendlist(arraylist<string> str) { setlistadapter(new bsadapter(this)); } public class bsadapter extends baseadapter { activity cntx; public bsadapter(activity context) { this.cntx = context; } public int getcount() { return array_sort.size(); } public object getitem(int position) { return array_sort.get(position); } public long getitemid(int position) { return array_sort.size(); } public view getview(final int position, view convertview, viewgroup parent) { view row = null; layoutinflater inflater = cntx.getlayoutinflater(); row = inflater.inflate(r.layout.search_country_listview, null); textview tv = (textview) row.findviewbyid(r.id.listview_seacrh_text); tv.settext(array_sort.get(position)); return row; } } }
problem here, call webview on static position, instead call accordingly array list below.
if( array_list.get(position).equals("afghanistan")){ intent intent = new intent(search_country.this, country_details.class); intent.putextra("header", getstring(r.string.html_afganistan)); startactivity(intent); }
Comments
Post a Comment