У меня есть RecyclerView
в Layout, и при нажатии на любой элемент в RecyclerView
открываться другой Layout где есть TextView
мне нужно в нем подменять текст.
Пробовал делать в адаптере RecyclerView
так:
holder.itemView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
SubCategory.mName.clear();
SubCategory.onSelectSubCategory(position);
TextView textView = v.findViewById(R.id.name_sub_category);
textView.setText(mName.get(position));
Intent intent = new Intent(v.getContext(), SubCategory.class);
v.getContext().startActivity(intent);
Toast.makeText(mContext, "Click to " + position + " position", Toast.LENGTH_SHORT).show();
}
});
Ошибка:
E/AndroidRuntime: FATAL EXCEPTION: main
Process: kz.sferagroup.fromcaappication, PID: 624
java.lang.NullPointerException: Attempt to invoke virtual method 'android.content.pm.ApplicationInfo android.content.Context.getApplicationInfo()' on a null object reference
at android.content.ContextWrapper.getApplicationInfo(ContextWrapper.java:173)
at android.view.ContextThemeWrapper.getTheme(ContextThemeWrapper.java:174)
at android.content.Context.obtainStyledAttributes(Context.java:747)
at androidx.appcompat.app.AppCompatDelegateImpl.createSubDecor(AppCompatDelegateImpl.java:839)
at androidx.appcompat.app.AppCompatDelegateImpl.ensureSubDecor(AppCompatDelegateImpl.java:806)
at androidx.appcompat.app.AppCompatDelegateImpl.findViewById(AppCompatDelegateImpl.java:630)
at androidx.appcompat.app.AppCompatActivity.findViewById(AppCompatActivity.java:223)
at kz.sferagroup.fromcaappication.SubCategory.onSelectSubCategory(SubCategory.java:56)
at kz.sferagroup.fromcaappication.CategoryRecyclerViewAdapter$1.onClick(CategoryRecyclerViewAdapter.java:48)
at android.view.View.performClick(View.java:7297)
at android.view.View.performClickInternal(View.java:7274)
at android.view.View.access$3600(View.java:819)
at android.view.View$PerformClick.run(View.java:28023)
at android.os.Handler.handleCallback(Handler.java:914)
at android.os.Handler.dispatchMessage(Handler.java:100)
at android.os.Looper.loop(Looper.java:225)
at android.app.ActivityThread.main(ActivityThread.java:7564)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:539)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:950)