Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/216.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/react-native/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何将文本从recyclerview适配器更新为其他布局xml_Java_Android - Fatal编程技术网

Java 如何将文本从recyclerview适配器更新为其他布局xml

Java 如何将文本从recyclerview适配器更新为其他布局xml,java,android,Java,Android,我在activity中有一个适配器AdapterAdapterServiceCourier。适配器类用于显示单选按钮 价格如何使用ActivityCheckout中的视图更新textview。 像 当我在适配器适配器服务浏览器中使用时: 其错误如下: E/UncaughtException: android.view.InflateException: Binary XML file line #9: Binary XML file line #9: Error inflating class

我在activity中有一个适配器AdapterAdapterServiceCourier。适配器类用于显示单选按钮 价格如何使用ActivityCheckout中的视图更新textview。 像

当我在适配器适配器服务浏览器中使用时:

其错误如下:

E/UncaughtException: android.view.InflateException: Binary XML file line #9: Binary XML file line #9: Error inflating class <unknown>
显示: 图像单击单选按钮,价格必须设置为ongkir价格
YourAdapter实例=新建YourAdaptercontext、arrayList、textView

现在,在适配器的构造函数中,您可以访问该文本视图

youradparter.java


现在,在适配器中,您可以更新textview值

这是可观察的设计模式:

您的活动应该实现观察者界面

您的适配器应该扩展Observable类

您应该将活动添加到适配器中

使用notiftyObserver方法,您可以更新活动


请注意,您可以通知多个活动。

在适配器类中单击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);
    }
};
在你的活动中,你可以在课堂上

添加静态方法不要错过这一点


您可以使用上下文将“活动”的方法访问到适配器中。在“活动”中创建一个带有字符串参数的方法,将字符串设置为您的文本视图,并在您的适配器中调用该方法,当您要更改文本时。

附加您的xml文件。错误不在代码中,错误主要在xml文件ActivityCheckout ac=new ActivityCheckout;您正在将文本设置到xml布局中未附加的TextView类中。您不能像这样创建新活动,操作系统将创建每个活动。您应该将活动的引用传递给适配器,并将文本放在该文本视图中
E/UncaughtException: android.view.InflateException: Binary XML file line #9: Binary XML file line #9: Error inflating class <unknown>
@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);
}
TextView textView;
YourAdapter(Context context,Arraylist<ModelClass> arraylist,TextView textView)
{
this.textView = textView;
} 
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);
    }
};
class ActivityCheckout
{
 .....
  //on create and etc
  public static void updateTextView(String DataUWantToUpadate)
  {
    yourTextViewObject.setText(DataUWantToUpdate);
  }

}