这是我在RecycleAdapternew类中使用tableDataReceived值的DataHolderNew类。
public class DataHolderNew extends RecyclerView.ViewHolder {
public TextView table_value;
static int tableDataReceived;
public DataHolderNew(View itemView) {
super(itemView);
table_value = (TextView) itemView.findViewById(R.id.table_values);
Context context = itemView.getContext();
Intent intent = ((Activity) context).getIntent();
tableDataReceived = intent.getIntExtra("transfer", 1);
}
}
这是RecycleAdapternew类,我在下面的行中遇到错误
public class RecyclerAdapterNew extends RecyclerView.Adapter<DataHolderNew> {
@Override
public DataHolderNew onCreateViewHolder(ViewGroup parent, int viewType) {
Context context = parent.getContext();
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View view = inflater.inflate(R.layout.table_values, parent, false);
return new DataHolderNew(view);
}
@Override
public void onBindViewHolder(DataHolderNew holder, int position) {
holder.table_value.setText((position + 1) * DataHolderNew.tableDataReceived); //error in this line
}
@Override
public int getItemCount() {
return 10;
}
}
答案 0 :(得分:1)
holder.table_value.setText((position + 1) * DataHolderNew.tableDataReceived); //error in this line
您正在尝试将Integer设置为TextView(holder.table_value)。 试试这个。
holder.table_value.setText(((position + 1) * DataHolderNew.tableDataReceived)+""); //make it a string and set it
希望这可以解决您的问题。