Я помещаю текстовое представление в Arraylist, и мне нужно щелкнуть текстовый просмотр, чтобы отобразить значение. Я бы хотел, чтобы значение отображалось без необходимости нажимать на текстовое изображение. и когда значение, которое оно изменяется, то, что отображается в texview, является старым значением, я должен щелкнуть текстовое представление, чтобы оно обновляло значение
все отображается хорошо, кроме:
holder.mTextprix.setText(CustomerMapActivity.calculate_item_price);
вот мой код
Адаптер, отвечающий за отображение типа автомобилей в CustomerActivity.class
public class TypeAdapter extends RecyclerView.Adapter<TypeAdapter.viewHolders> {
private Context context;
private TypeObject selectedItem;
private List<TypeObject> itemArrayList;
public TypeAdapter(List<TypeObject> itemArrayList, Context context) {
this.itemArrayList = itemArrayList;
selectedItem = itemArrayList.get(0);
this.context = context;
}
@Override
public TypeAdapter.viewHolders onCreateViewHolder(ViewGroup parent, int viewType) {
View layoutView = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_type, null, false);
RecyclerView.LayoutParams lp = new RecyclerView.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
layoutView.setLayoutParams(lp);
TypeAdapter.viewHolders rcv = new TypeAdapter.viewHolders(layoutView);
return rcv;
}
/**
* Bind view to holder, setting the text to
* the design elements
* @param position - current position of the recyclerView
*/
@Override
public void onBindViewHolder(final @NonNull viewHolders holder, int position) {
holder.mName.setText(itemArrayList.get(position).getName());
holder.mPeople.setText(String.valueOf(itemArrayList.get(position).getPeople()));
holder.mImage.setImageDrawable(itemArrayList.get(position).getImage());
holder.mTextprix.setText(CustomerMapActivity.calculate_item_price);
if(selectedItem.equals(itemArrayList.get(position))){
holder.mLayout.setBackgroundColor(context.getResources().getColor(R.color.colorAccent2));
}else{
holder.mLayout.setBackgroundColor(context.getResources().getColor(R.color.white));
}
holder.mLayout.setOnClickListener(v -> {
selectedItem = itemArrayList.get(holder.getAdapterPosition());
notifyDataSetChanged();
});
}
public TypeObject getSelectedItem() {
return selectedItem;
}
public void setSelectedItem(TypeObject selectedItem) {
this.selectedItem = selectedItem;
}
@Override
public int getItemCount() {
return this.itemArrayList.size();
}
/**
* Responsible for handling the data of each view
*/
class viewHolders extends RecyclerView.ViewHolder {
TextView mName,
mPeople,
mTextprix;
ImageView mImage;
LinearLayout mLayout;
viewHolders(View itemView) {
super(itemView);
mImage = itemView.findViewById(R.id.image);
mPeople = itemView.findViewById(R.id.people);
mName = itemView.findViewById(R.id.name);
mLayout = itemView.findViewById(R.id.layout);
mTextprix = itemView.findViewById(R.id.prixprix);
}
}
}
public class Utils {
/**
* Round a float value to a specific decimal place
* @param amount - the value to round
* @param decimalPlace - to what decimal place to round the amount to
* @return rounded number
*/
public BigDecimal round(float amount, int decimalPlace) {
BigDecimal bd = new BigDecimal(Float.toString(amount));
bd = bd.setScale(decimalPlace, BigDecimal.ROUND_HALF_UP);
return bd;
}
/**
* Returns array list with all of the driver rides available for this
* application.
* @param activity - activity that called this function
* @return typeArrayList - array list with all the driver types
*/
public static ArrayList<TypeObject> getTypeList(Activity activity){
ArrayList<TypeObject> typeArrayList = new ArrayList<>();
typeArrayList.add(new TypeObject("type_1", activity.getResources().getString(R.string.type_1), activity.getResources().getDrawable(R.drawable.ic_type_1), 3));
return typeArrayList;
}
public static TypeObject getTypeById(Activity activity, String id){
ArrayList<TypeObject> typeArrayList = getTypeList(activity);
for(TypeObject mType : typeArrayList){
if(mType.getId().equals(id)){
return mType;
}
}
return null;
}
}
И
public class TypeObject {
String name, id;
Drawable image;
int people;
public TypeObject(String id, String name, Drawable image, int people){
this.id = id;
this.name = name;
this.image = image;
this.people = people;
}
public String getId() {
return id;
}
public Drawable getImage() {
return image;
}
public String getName() {
return name;
}
public int getPeople() {
return people;
}
}