英文:
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<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);
}
}
}
专注分享java语言的经验与见解,让所有开发者获益!
评论