我在活动中有ActivityCheckout.java,一个适配器AdapterServiceCourier。适配器类用于显示单选按钮的价格.如何用textview中的视图更新ActivityCheckout。喜欢
public TextView getTextViewPriceOngkir()
{
TextView txtView = (TextView)findViewById(R.id.price_ongkir);
return txtView;
}当我在适配器AdapterServiceCourier中使用
ActivityCheckout ac = new ActivityCheckout();
TextView tv = ac.getTextViewPriceOngkir();
tv.setText("8");它的错误就像:
E/UncaughtException: android.view.InflateException: Binary XML file line #9: Binary XML file line #9: Error inflating class <unknown>AdapterServiceCourier.java:
@Override
public void onBindViewHolder(final ViewHolder holder, final int position) {
SharedPreferences sharedPreferences = context.getSharedPreferences(AppConfig.APP_PUPUKKUJANG_MART, Context.MODE_PRIVATE);
final String whois = sharedPreferences.getString(AppConfig.USER_WHOIS,null);
row_index = -1;
holder.itemView.setTag(service.get(position));
final ServiceCourier p = service.get(position);
holder.service.setText(p.getService());
holder.desc.setText(p.getDescription());
holder.cost.setText(p.getCost());
holder.etd.setText(p.getEtd());
holder.itemView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
}
});
View.OnClickListener rbClick = new View.OnClickListener() {
@Override
public void onClick(View v) {
RadioButton checked_rb = (RadioButton) v;
if(lastCheckedRB != null){
lastCheckedRB.setChecked(false);
}
lastCheckedRB = checked_rb;
SharedPreferences sharedPreferences = context.getSharedPreferences(AppConfig.APP_PUPUKKUJANG_MART, Context.MODE_PRIVATE);
SharedPreferences.Editor editor = sharedPreferences.edit();
editor.putString("ongkir_service", p.getService());
editor.putString("ongkir_description", p.getDescription());
editor.putString("ongkir_cost", p.getCost());
editor.putString("ongkir_etd", p.getEtd());
editor.apply();
ActivityCheckout ac = new ActivityCheckout();
TextView tv = ac.getTextViewPriceOngkir();
tv.setText("8");
}
};
holder.radiobutton.setOnClickListener(rbClick);
}显示:图像单击单选按钮,价格必须设置为ongkir价格在这里输入图像描述
发布于 2018-09-10 06:50:57
在适配器类OnClick RadioButton中
View.OnClickListener rbClick = new View.OnClickListener() {
@Override
public void onClick(View v) {
RadioButton checked_rb = (RadioButton) v;
if(lastCheckedRB != null){
lastCheckedRB.setChecked(false);
}
.....
.....
//Create Statis Mathod in ActivityCheckout and Access Hear
ActivityCheckout.updateTextView(String DataUWantToAdd);
}
};在Yout ActivityCheckout类中
添加静态方法不要错过那个
class ActivityCheckout
{
.....
//on create and etc
public static void updateTextView(String DataUWantToUpadate)
{
yourTextViewObject.setText(DataUWantToUpdate);
}
}发布于 2018-09-10 04:34:37
这是可观察的设计模式:
notiftyObserver方法,您可以更新活动请注意,使用这种设计模式,您可以通知多个活动。
发布于 2018-09-10 04:24:39
YourAdapter实例=新YourAdapter(context,arrayList,textView);
现在,在适配器的构造函数中,您可以访问该文本视图。
YourAdpater.java
TextView textView;
YourAdapter(Context context,Arraylist<ModelClass> arraylist,TextView textView)
{
this.textView = textView;
} 现在,在适配器中,您可以更新textview值。
https://stackoverflow.com/questions/52251035
复制相似问题