android – Error while add more than one layout or textview while filter list?-ThrowExceptions

Exception or error:

I am getting an error when I would add more than one layout in XML it provides filter list from google search places API

    edtDropLocation.setAdapter(new GooglePlacesAutocompleteAdapterNew(getActivity(), R.layout.list_item_text));
    edtDropLocation.setOnItemClickListener(this);

   class GooglePlacesAutocompleteAdapterNew extends ArrayAdapter implements Filterable {
    private ArrayList resultList;


    public GooglePlacesAutocompleteAdapterNew(Context context, int textViewResourceId) {
        super(context, textViewResourceId);
    }
    @Override
    public int getCount() {
        return resultList.size();
    }
    @Override
    public Object getItem(int index) {
        return resultList.get(index);
    }

    @Override
    public Filter getFilter() {
        Filter filter = new Filter() {
            @Override
            protected FilterResults performFiltering(CharSequence constraint) {
                FilterResults filterResults = new FilterResults();
                if (constraint != null) {
                    resultList = autocomplete(constraint.toString());
                    filterResults.values = resultList;
                    filterResults.count = resultList.size();
                }
                return filterResults;
            }

            @Override
            protected void publishResults(CharSequence constraint, FilterResults results) {
                if (results != null && results.count > 0) {
                    notifyDataSetChanged();
                } else {
                    notifyDataSetInvalidated();
                }
            }
        };
        return filter;
    }
}
public static ArrayList autocomplete(String input) {
    ArrayList resultList = null;
    HttpURLConnection conn = null;
    StringBuilder jsonResults = new StringBuilder();
    try {
        StringBuilder sb = new StringBuilder(PLACES_API_BASE + TYPE_AUTOCOMPLETE + OUT_JSON);
        sb.append("?key=" + API_KEY);
        sb.append("&components=country:in");
        sb.append("&input=" + URLEncoder.encode(input, "utf8"));
        Log.e("@@sb", sb.toString());
        URL url = new URL(sb.toString());
        conn = (HttpURLConnection) url.openConnection();
        InputStreamReader in = new InputStreamReader(conn.getInputStream());
        int read;
        char[] buff = new char[1024];
        while ((read = in.read(buff)) != -1) {
            jsonResults.append(buff, 0, read);
        }
    } catch (MalformedURLException e) {
        Log.e("@@", "Error processing Places API URL", e);
        return resultList;
    } catch (IOException e) {
        Log.e("@@", "Error connecting to Places API", e);
        return resultList;
    } finally {
        if (conn != null) {
            conn.disconnect();
        }
    }
    try {
        JSONObject jsonObj = new JSONObject(jsonResults.toString());
        JSONArray predsJsonArray = jsonObj.getJSONArray("predictions");
        resultList = new ArrayList(predsJsonArray.length());
        for (int i = 0; i < predsJsonArray.length(); i++) {
            System.out.println(predsJsonArray.getJSONObject(i).getString("description"));
            System.out.println("====");
            resultList.add(predsJsonArray.getJSONObject(i).getString("description"));
        }
    } catch (JSONException e) {
        Log.e("@@", "Cannot process JSON results", e);
    }
    return resultList;
}

and this is my layout

   <?xml version="1.0" encoding="utf-8"?>
   <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/rlytSearch"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="10dp" >
<com.truck.userside.fonts.OpenSensMedium

android:textSize="20sp"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" />

I am getting error like this

 E/ArrayAdapter: You must supply a resource ID for a TextView

when I have only textview It is working but it is not working with any other layout

please suggest this I would appreciate every answer thank you in advance

How to solve:

Leave a Reply

Your email address will not be published. Required fields are marked *