List<Hashmap<String,String> data setting in RecyclerView adapter

huangapple 未分类评论45阅读模式
英文:

List<Hashmap<String,String> data setting in RecyclerView adapter

问题

我想在TextView中添加以下字符串数据。由于我是新学习者,所以不知道如何添加。请帮助我。我想在TextView中添加地点名称、地址和评分。DisplayNearByplaces() 方法与 onPostExecute() 方法相连接。

public class PlaceAdapter extends RecyclerView.Adapter<PlaceAdapter.MyViewHolder> {
    List<String> data;
    Context context;

    public PlaceAdapter(List<String> data, Context context) {
        this.data = data;
        this.context = context;
    }

    @NonNull
    @Override
    public MyViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        return new MyViewHolder(LayoutInflater.from(context).inflate(R.layout.details_row, parent, false));
    }

    @Override
    public void onBindViewHolder(@NonNull MyViewHolder holder, int position) {

    }

    @Override
    public int getItemCount() {
        return data.size();
    }

    public void DisplayNearByPlaces(List<HashMap<String, String>> nearByPlacesList) {

        for (int i = 0; i < nearByPlacesList.size(); i++) {

            HashMap<String, String> googleNearByPlaces = nearByPlacesList.get(i);
            String nameOfPlace = googleNearByPlaces.get("place_name");
            String vicinity = googleNearByPlaces.get("vicinity");
            String reference = googleNearByPlaces.get("reference");
            double lat = Double.parseDouble(googleNearByPlaces.get("lat"));
            double lng = Double.parseDouble(googleNearByPlaces.get("lng"));
            String address = googleNearByPlaces.get("formatted_address");
            String rating = googleNearByPlaces.get("rating");


        }


    }

    public class MyViewHolder extends RecyclerView.ViewHolder {
        TextView t1, t2, t3, t4;
        Button sel;
        ImageButton gmap;

        public MyViewHolder(@NonNull View itemView) {
            super(itemView);
            t1 = (TextView) itemView.findViewById(R.id.place_name);
            t2 = (TextView) itemView.findViewById(R.id.address);
            t3 = (TextView) itemView.findViewById(R.id.distance);
            t4 = (TextView) itemView.findViewById(R.id.rating);

            sel = (Button) itemView.findViewById(R.id.sel_place);
            gmap = (ImageButton) itemView.findViewById(R.id.map_place);
        }
    }
}
英文:

I want to add the following String datas in the textview. As I am new learner so I can't understand how add those. Please help me. I want to add nameOfplace,address,rating in the textview. DisplayNearByplaces()
method is connected to the onPostExecute() method.

    public class PlaceAdapter extends RecyclerView.Adapter&lt;PlaceAdapter.MyViewHolder&gt; {
    List&lt;String&gt; data;
    Context context;

    public PlaceAdapter(List&lt;String&gt; data, Context context) {
        this.data = data;
        this.context = context;
    }

    @NonNull
    @Override
    public MyViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        return new MyViewHolder(LayoutInflater.from(context).inflate(R.layout.details_row, parent, false));
    }

    @Override
    public void onBindViewHolder(@NonNull MyViewHolder holder, int position) {

    }

    @Override
    public int getItemCount() {
        return data.size();
    }

    public void DisplayNearByPlaces(List&lt;HashMap&lt;String, String&gt;&gt; nearByPlacesList) {

        for (int i = 0; i &lt; nearByPlacesList.size(); i++) {

            HashMap&lt;String, String&gt; googleNearByPlaces = nearByPlacesList.get(i);
            String nameOfPlace = googleNearByPlaces.get(&quot;place_name&quot;);
            String vicinity = googleNearByPlaces.get(&quot;vicinity&quot;);
            String reference = googleNearByPlaces.get(&quot;reference&quot;);
            double lat = Double.parseDouble(googleNearByPlaces.get(&quot;lat&quot;));
            double lng = Double.parseDouble(googleNearByPlaces.get(&quot;lng&quot;));
            String address = googleNearByPlaces.get(&quot;formatted_address&quot;);
            String rating = googleNearByPlaces.get(&quot;rating&quot;);
            
            
        }


    }

    public class MyViewHolder extends RecyclerView.ViewHolder {
        TextView t1, t2, t3, t4;
        Button sel;
        ImageButton gmap;

        public MyViewHolder(@NonNull View itemView) {
            super(itemView);
            t1 = (TextView) itemView.findViewById(R.id.place_name);
            t2 = (TextView) itemView.findViewById(R.id.address);
            t3 = (TextView) itemView.findViewById(R.id.distance);
            t4 = (TextView) itemView.findViewById(R.id.rating);

            sel = (Button) itemView.findViewById(R.id.sel_place);
            gmap = (ImageButton) itemView.findViewById(R.id.map_place);
        }
    }
}

huangapple
  • 本文由 发表于 2020年4月6日 23:08:42
  • 转载请务必保留本文链接:https://java.coder-hub.com/61062888.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定