I get the response from the server and show it using listview, and it works fine, now I try to add autocompletetextview to search for items by name, but when I run my application it crashes and shows errors .. I already ask this
Tab1Activity.java
public class Tab1Activity extends ListActivity{ private ProgressDialog pDialog; JSONArray Product=null; private ListView listview; ArrayList<HashMap<String,String>> aList; ArrayList<HashMap<String, String>> arrayTemplist; private static String PRODUCT_URL = ""; private static final String PRODUCT_DATA="Product"; private static final String PRODUCT_ID="productid"; private static final String PRODUCT_NAME="product_name"; private static final String PRODUCT_CODE="skucode"; private static final String PRODUCT_IMAGE="product_photo"; private static final String PRODUCT_WEIGHT="weight"; private static final String PRODUCT_SALERATE="sale_rate"; //private static final String PRODUCT_LOCATION="weight"; private CustomAdapterTabone adapter; private TextView noacpt; private AutoCompleteTextView inputSearch; @Override protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); setContentView(R.layout.list_view_tabone); //noacpt=(TextView)findViewById(R.id.no_acceptedlist); /*String strtext = getIntent().getStringExtra("id"); System.out.println("<<<<<<<< id : " + strtext);*/ final ListView listview = (ListView)findViewById(android.R.id.list); //listview.setSelector( R.drawable.list_selector); //listview.setSelector(R.drawable.listselector); new LoadAlbums().execute(); aList = new ArrayList<HashMap<String, String>>(); final ListView lv = getListView(); inputSearch = (AutoCompleteTextView) findViewById(R.id.autoCompleteTextView1); inputSearch.addTextChangedListener(new TextWatcher() { @Override public void onTextChanged(CharSequence cs, int arg1, int arg2, int arg3) { arrayTemplist= new ArrayList<HashMap<String,String>>(); String searchString =inputSearch.getText().toString().toLowerCase(); for (int i = 0; i < aList.size(); i++) { String currentString =aList.get(i).get(Tab1Activity.PRODUCT_NAME); if (currentString.toLowerCase().startsWith(searchString )) { arrayTemplist.add(aList.get(i)); } } for (int i = 0; i < arrayTemplist.size(); i++) { String currentstrin = arrayTemplist.get(i).get(Tab1Activity.PRODUCT_NAME); //Toast.makeText(getApplicationContext(), currentstrin, Toast.LENGTH_LONG).show(); } adapter=new CustomAdapterTabone(getApplicationContext(), arrayTemplist); listview.setAdapter(adapter); /* SimpleAdapter adapters = new SimpleAdapter(Tab1Activity.this, arrayTemplist,R.layout.list_item_tabone, new String[] { PRODUCT_NAME }, new int[] { R.id.txtpronameacptedlist}); lv.setAdapter(adapters); */ } @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 } }); } @Override public void onListItemClick(ListView l, View v, int position, long id) { Intent intent = new Intent(getApplicationContext(), AllProductDetails.class); intent.putExtra("productid", aList.get(position).get(PRODUCT_ID)); startActivity(intent); } class LoadAlbums extends AsyncTask<String, String, ArrayList<HashMap<String,String>>> { /** * Before starting background thread Show Progress Dialog * */ @Override protected void onPreExecute() { super.onPreExecute(); pDialog = new ProgressDialog(Tab1Activity.this); pDialog.setMessage("Loading..."); pDialog.setIndeterminate(true); // pDialog.setIndeterminateDrawable(getResources().getDrawable(R.drawable.custom_progress)); pDialog.setCancelable(false); pDialog.show(); } protected ArrayList<HashMap<String,String>> doInBackground(String... args) { ServiceHandler sh = new ServiceHandler(); // Making a request to url and getting response ArrayList<HashMap<String,String>> data = new ArrayList<HashMap<String, String>>(); String jsonStr = sh.makeServiceCall(PRODUCT_URL, ServiceHandler.GET); Log.d("Response: ", "> " + jsonStr); if (jsonStr != null) { try { JSONObject jsonObj = new JSONObject(jsonStr); // Getting JSON Array node Product = jsonObj.getJSONArray(PRODUCT_DATA); for (int i = 0; i < Product.length(); i++) { JSONObject c = Product.getJSONObject(i); // creating new HashMap HashMap<String, String> map = new HashMap<String, String>(); // adding each child node to HashMap key => value map.put(PRODUCT_ID, c.getString(PRODUCT_ID)); map.put(PRODUCT_NAME,c.getString(PRODUCT_NAME)); map.put(PRODUCT_CODE, c.getString(PRODUCT_CODE)); map.put(PRODUCT_IMAGE, c.getString(PRODUCT_IMAGE)); map.put(PRODUCT_WEIGHT, c.getString(PRODUCT_WEIGHT)); map.put(PRODUCT_SALERATE, c.getString(PRODUCT_SALERATE)+getResources().getString(R.string.rupee)); // map.put(INTEREST_ACCEPT_LOCATION, c.getString(INTEREST_ACCEPT_LOCATION)); // adding HashList to ArrayList data.add(map); } } catch (JSONException e) { e.printStackTrace(); } } else { Log.e("ServiceHandler", "Couldn't get any data from the url"); } return data; } protected void onPostExecute(ArrayList<HashMap<String,String>> result) { super.onPostExecute(result); // dismiss the dialog after getting all albums if (pDialog.isShowing()) pDialog.dismiss(); // updating UI from Background Thread aList = new ArrayList<HashMap<String, String>>(); aList.addAll(result); adapter = new CustomAdapterTabone(getApplicationContext(),result); setListAdapter(adapter); aList.addAll(result); adapter.notifyDataSetChanged(); }
}
Customadapter
public class CustomAdapterTabone extends BaseAdapter{ private Context context; private ArrayList<HashMap<String,String>> listData; private AQuery aQuery; private static final String TAG_NAME="product_name"; private static final String TAG_PROFILE="skucode"; private static final String TAG_IMAGE="product_photo"; private static final String TAG_CAST="weight"; private static final String TAG_AGE="sale_rate";