View to global class variable? - java

why the "view" in this lane is always red..
final TextView username = (TextView) view.findViewById(R.id.profile_username);
I always get this error like below:
"error: cannot find symbol variable view"
Sample code which I tried:
ProfileFragment class:
public class ProfileFragment extends Fragment {
MyBroadcastReceiver myReceiver = new MyBroadcastReceiver();
#Nullable
#Override
public View onCreateView(#NonNull LayoutInflater inflater, #Nullable ViewGroup container, #Nullable Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_profile, container, false);
ImageView profilsettings = (ImageView) view.findViewById(R.id.profile_toolbar_image);
profilsettings.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
BottomSheetDialog bottomSheetDialog = new BottomSheetDialog();
bottomSheetDialog.show(getFragmentManager(), bottomSheetDialog.getTag());
}
});
return view;
}
public class MyBroadcastReceiver extends BroadcastReceiver {
#Override
public void onReceive(Context context, Intent intent) {
if(intent.getAction().equals("my_broadcast")){
final TextView username = (TextView) view.findViewById(R.id.profile_username);
username.setText(intent.getStringExtra("name"));
}
}
}
#Override
public void onResume() {
super.onResume();
getActivity().registerReceiver(myReceiver, new IntentFilter("my_broadcast"));
}
#Override
public void onPause() {
super.onPause();
getActivity().unregisterReceiver(myReceiver);
}
}
Can anyone help me what do I have to change?
Thanks a lot!

It is happening because the variable view is not accessible to your BroadcastReceiver. So the compiler is saying error: cannot find symbol variable view
To make view accessible to BroadcastReceiver you can follow #Amine answer or you can easily make view asmember variable.
Make view object as a member variable like below
public class ProfileFragment extends Fragment {
MyBroadcastReceiver myReceiver = new MyBroadcastReceiver();
private View view;
#Nullable
#Override
public View onCreateView(#NonNull LayoutInflater inflater, #Nullable ViewGroup container, #Nullable Bundle savedInstanceState) {
view = inflater.inflate(R.layout.fragment_profile, container, false);
ImageView profilsettings = (ImageView) view.findViewById(R.id.profile_toolbar_image);
profilsettings.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
BottomSheetDialog bottomSheetDialog = new BottomSheetDialog();
bottomSheetDialog.show(getFragmentManager(), bottomSheetDialog.getTag());
}
});
return view;
}
public class MyBroadcastReceiver extends BroadcastReceiver {
#Override
public void onReceive(Context context, Intent intent) {
if(intent.getAction().equals("my_broadcast")){
final TextView username = (TextView) view.findViewById(R.id.profile_username);
username.setText(intent.getStringExtra("name"));
}
}
}
#Override
public void onResume() {
super.onResume();
getActivity().registerReceiver(myReceiver, new IntentFilter("my_broadcast"));
}
#Override
public void onPause() {
super.onPause();
getActivity().unregisterReceiver(myReceiver);
}
}
Happy coding!!

You need to get the TextView using the available context like this
final TextView username = (TextView) ((Activity) context).findViewById(R.id.profile_username);

Related

Need help getting a Toast to appear on a Tab Fragment

I'm trying to get a Toast to appear in a tabbed fragment when an EditText is left empty.
Here is my MainActivity's onCreate:
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
SectionsPagerAdapter sectionsPagerAdapter = new SectionsPagerAdapter(this, getSupportFragmentManager());
ViewPager viewPager = findViewById(R.id.view_pager);
viewPager.setAdapter(sectionsPagerAdapter);
TabLayout tabs = findViewById(R.id.tabs);
tabs.setupWithViewPager(viewPager);
}
}
My Tabbed Fragment works fine with this code:
public class SignupFragment extends Fragment {
#Nullable
#Override
public View onCreateView(#NonNull LayoutInflater inflater, #Nullable ViewGroup container, #Nullable Bundle savedInstanceState) {
return inflater.inflate(R.layout.fragment_signup, container, false);
}
}
But it doesn't work when creating the Toast like this:
public class SignupFragment extends Fragment {
EditText textFillCheck;
Button submitCheck;
#Nullable
#Override
public View onCreateView(#NonNull LayoutInflater inflater, #Nullable ViewGroup container, #Nullable Bundle savedInstanceState) {
submitCheck = (Button) submitCheck.findViewById(R.id.signupBtn);
textFillCheck = (EditText) textFillCheck.findViewById(R.id.signupFirstName);
submitCheck.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
if (TextUtils.isEmpty(textFillCheck.getText().toString())) {
Intent intent = new Intent(getActivity(), SignupFragment.class);
startActivity(intent);
Toast.makeText(getActivity(), "Please fill in all fields", Toast.LENGTH_SHORT).show();
}
else{Toast.makeText(getActivity(), textFillCheck.getText().toString(), Toast.LENGTH_LONG).show();
}
}
});
return inflater.inflate(R.layout.fragment_signup, container, false);
}
}
You're not accessing the views of your Fragment's layout so the layout you're returning in onCreateView() doesn't have your logic attached to it. You should set up your Fragment to look something like this:
public class SignupFragment extends Fragment {
EditText textFillCheck;
Button submitCheck;
#Nullable
#Override
public View onCreateView(#NonNull LayoutInflater inflater, #Nullable ViewGroup container, #Nullable Bundle savedInstanceState){
// Store a reference to your Fragment's inflated layout
View root = inflater.inflate(R.layout.fragment_signup, container, false);
// Use the reference to access your Fragment's views
submitCheck = (Button) root.findViewById(R.id.signupBtn);
textFillCheck = (EditText) root.findViewById(R.id.signupFirstName);
submitCheck.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
if(TextUtils.isEmpty(textFillCheck.getText().toString())) {
Toast.makeText(getActivity(), "Please fill in all fields", Toast.LENGTH_SHORT).show();
}else{
Toast.makeText(getActivity(), textFillCheck.getText().toString(), Toast.LENGTH_LONG).show();
}
}
});
// Return the inflated layout
return root;
}
}
I am amazed why your code is not having any error like VIEW DOES NOT EXIST or NULL POINTER EXCEPTION because
First, you change the activity before showing the Toast secondly you are inflating the layout after the initialization of views and not getting the context properly, Right way of doing what you are trying to achieve is using OnViewCreated() like this
#Override
public void onViewCreated(#NonNull View view, #Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
submitCheck = (Button) view.findViewById(R.id.signupBtn);
textFillCheck = (EditText) view.findViewById(R.id.signupFirstName);
submitCheck.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
if (TextUtils.isEmpty(textFillCheck.getText().toString())) {
Toast.makeText(getActivity(), "Please fill in all fields",
Toast.LENGTH_SHORT).show();
Intent intent = new Intent(getActivity(), SignupFragment.class);
startActivity(intent);
}
else{
Toast.makeText(getActivity(), textFillCheck.getText().toString(),
Toast.LENGTH_LONG).show();
}
}
});
}

how to settext button in bottom sheet dialog fragment?

i have one class for bottomsheetdialog fragment.I looked at many places but I'm confused.i want to change text of button in bottom sheet.i get this error 'android.view.View android.view.View.findViewById(int)' on a null object reference.
here are my codes;
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(final Bundle savedInstanceState) {
bottomSheetFragment=new BottomSheetFragment();
View viewDialog=bottomSheetFragment.getView();
assert viewDialog != null;
MaterialButton btn_titresim=viewDialog.findViewById(R.id.btn_titresim);
btn_titresim.setText("text");
}
}
Another class for BottomSheetDialogFragment
public class BottomSheetFragment extends BottomSheetDialogFragment {
public BottomSheetFragment() {}
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
Objects.requireNonNull(getDialog()).setOnShowListener(dialog -> {
BottomSheetDialog d = (BottomSheetDialog) dialog;
View bottomSheetInternal =
d.findViewById(com.google.android.material.R.id.design_bottom_sheet);
assert bottomSheetInternal != null;
BottomSheetBehavior.from(bottomSheetInternal).setState(BottomSheetBehavior.STATE_EXPANDED);
});
return inflater.inflate(R.layout.layout_popup, container, false);
}
}
You can solve this by having a listener interface in your fragment that returns the BottomSheet fragment's View back to your activity, so you can then access the BottomSheetDialogFragmentunderlying views normally by findViewById() method.
Here I decided to use the Singleton pattern for the BottomSheetDialogFragment to set a listener instance from the activity.
So in your fragment add a listener; it's named below FragmentListener, call the listener callback in onCreateView() or in onViewCreated()
public class BottomSheetFragment extends BottomSheetDialogFragment {
public BottomSheetFragment() {}
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
interface FragmentListener {
void getView(View view);
}
static FragmentListener mFragmentListener;
public static BottomSheetFragment newInstance(FragmentListener listener) {
mFragmentListener = listener;
return new BottomSheetFragment();
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
Objects.requireNonNull(getDialog()).setOnShowListener(dialog -> {
BottomSheetDialog d = (BottomSheetDialog) dialog;
View bottomSheetInternal =
d.findViewById(com.google.android.material.R.id.design_bottom_sheet);
assert bottomSheetInternal != null;
BottomSheetBehavior.from(bottomSheetInternal).setState(BottomSheetBehavior.STATE_EXPANDED);
});
View view = inflater.inflate(R.layout.layout_popup, container, false);
// Trigger the listener callback to return the view back to the activity
// mFragmentListener.getView(view); // Not working in all devices
return inflater.inflate(R.layout.layout_popup, container, false);
}
#Override
public void onViewCreated(#NonNull View view, #Nullable Bundle savedInstanceState) {
// Trigger the listener callback to return the view back to the activity
mFragmentListener.getView(view);
}
}
implement the listener by your activity, and change the text in your callback, and instantiate the BottomSheetDialogFragment using the singleton pattern instead.
public class MainActivity extends AppCompatActivity implements BottomSheetFragment.FragmentListener {
#Override
protected void onCreate(final Bundle savedInstanceState) {
bottomSheetFragment = BottomSheetFragment.newInstance(this);
}
#Override
public void getView(View view) {
// Setting the text
((MaterialButton) view.findViewById(R.id.btn_titresim)).setText("text");
}
}
Wish that solves your problem

I want to Send Data Activity to fragment But InterFace Method Never Called

i implements my interface in Two fragments i want to send Data from Activity to both Fragments..when i do this my data send in Second Fragment not in First Fragment. it called only Second Fragments interface method..not call first Fragment interface method i d'nt UnderStand Please Some One Help....
This is Main Activity
public class MainActivity extends AppCompatActivity implements FragmentCommunication {
TextView textView;
ReceiveMessage receiveMessage;
EditText editText;
Button button;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
textView = findViewById(R.id.textAcitivity);
editText = findViewById(R.id.editActivity);
button = findViewById(R.id.buttonActivity);
if (findViewById(R.id.fragment1)!= null)
{
if (savedInstanceState != null)
{
return;
}
}
FirstFragment firstFragment = new FirstFragment();
SecondFragment secondFragment = new SecondFragment();
FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction()
.add(R.id.fragment1, firstFragment, null);
fragmentTransaction.commit();
FragmentTransaction fragmentTransaction1 = getSupportFragmentManager().beginTransaction().add(R.id.fragment2, secondFragment,null);
fragmentTransaction1.commit();
button.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
String name = editText.getText().toString().trim();
receiveMessage.receiveMessage(name, 3);
}
});
}
#Override
public void onAttachFragment(#NonNull Fragment fragment) {
super.onAttachFragment(fragment);
try {
receiveMessage = (ReceiveMessage) fragment;
} catch (ClassCastException e) {
throw new ClassCastException(fragment.toString() + " must implement receiveMessage..");
}
}
}
This is my interface
public interface ReceiveMessage {
void receiveMessage(String message, int from);
}
This is my First Fragment
public class FirstFragment extends Fragment implements ReceiveMessage {
private View view;
private TextView textView;
private EditText editText;
private Button button;
#Nullable
#Override
public View onCreateView(#NonNull LayoutInflater inflater, #Nullable ViewGroup container, #Nullable Bundle savedInstanceState) {
view = inflater.inflate(R.layout.firstfragment, container, false);
textView = view.findViewById(R.id.textView10);
editText = view.findViewById(R.id.Edit1);
button = view.findViewById(R.id.button1);
return view;
}
#Override
public void receiveMessage(String message, int from) { // THIS METHOD NAVER CALLED WHEN I SEND dATA
FROM aCTIVITY
if (from == 3)
{
textView.setText(message);
}
}
}
This is my Second Fragment
public class SecondFragment extends Fragment implements ReceiveMessage {
private View view;
private TextView textView;
private EditText editText;
private Button button;
#Nullable
#Override
public View onCreateView(#NonNull LayoutInflater inflater, #Nullable ViewGroup container, #Nullable Bundle savedInstanceState) {
view = inflater.inflate(R.layout.secondfragment, container, false);
textView = view.findViewById(R.id.textView2);
editText = view.findViewById(R.id.editText2);
button = view.findViewById(R.id.button);
return view;
}
#Override
public void receiveMessage(String message, int from) {
if (from == 3)
{
textView.setText(message);
}
}
}
Every time when you add a new fragment, the "onAttachFragment" of activity gets called again. So when you added the second fragment, you resetted the value of "receiveMessage" object to the interface implementation of second fragment.Hence you should rewrite your code as :
ReceiveMessage firstReceiver;
ReceiveMessage secondReceiver;
#Override
public void onAttachFragment(Fragment fragment) {
super.onAttachFragment(fragment);
if (fragment instanceof FirstFragment) {
firstReceiver = (ReceiveMessage) fragment;
} else if (fragment instanceof SecondFragment) {
secondReceiver = (ReceiverMessage) fragment;
}
}
button.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
String name = editText.getText().toString().trim();
firstReceiver.receiveMessage(name, 3);
secondReceiver.receiveMessage(name, 3);
}
});

Why is my code always receiving a null pointer exception when I have binded the element in to it? I am using Java in Android Studio

I am receiving java.lang.NullPointerException, although I have binded the element correctly.
Tried to check the ID of the element, it matches, but still I receive the same exception.
MainActivity.java
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//Text to Speech
tts = new TextToSpeech(this, this);
speakButton = findViewById(R.id.speakButton);
speechText = findViewById(R.id.speechText);
speakButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
speakOut();
}
});
// End
loadFragment(new HomeFragment());
BottomNavigationView navigation = findViewById(R.id.navigation);
navigation.setOnNavigationItemSelectedListener(mOnNavigationItemSelectedListener);
}
TranslatorFragment.java
public class TranslatorFragment extends Fragment {
public Button speakButton;
public TranslatorFragment(){
//Empty Constructor
}
#Override
public View onCreateView(#NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
return inflater.inflate(R.layout.translator_fragment, container, false);
}
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
}
#Override
public void onViewCreated(#NonNull View view, #Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
speakButton = view.findViewById(R.id.speakButton);
}
}
It should be running fine, But I am receiving the java.lang.NullPointerException
You button code should be declared in you fragment not in you activity as the button is in your fragment.xml. As you are accessing the button in onCreate method of the activity it will give nullpointer exception because you fragment's view is not yet rendered.The best practice is to access the view in onViewCreated function of your fragment.
MainActivity.java
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
loadFragment(new HomeFragment());
BottomNavigationView navigation = findViewById(R.id.navigation);
navigation.setOnNavigationItemSelectedListener(mOnNavigationItemSelectedListener);
}
TranslatorFragment.java
public class TranslatorFragment extends Fragment {
public Button speakButton;
public TranslatorFragment(){
//Empty Constructor
}
#Override
public View onCreateView(#NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
return inflater.inflate(R.layout.translator_fragment, container, false);
}
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
}
#Override
public void onViewCreated(#NonNull View view, #Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
//Text to Speech
tts = new TextToSpeech(getActivity(), this);
speakButton = findViewById(R.id.speakButton);
speechText = findViewById(R.id.speechText);
speakButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
speakOut();
}
});
// End
}
void speakOut(){
}
The solution is to implement TextToSpeech.OnInitListener in the project and make the public variables to be private.
public class TranslatorFragment extends Fragment implements TextToSpeech.OnInitListener{
private Button speakButton; // public Button speakButton;
private TextToSpeech tts;
private EditText speechText; // public EditText speechText;
public TranslatorFragment(){
//Empty Constructor
}
#Override
public View onCreateView(#NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
return inflater.inflate(R.layout.translator_fragment, container, false);
}
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
}
#Override
public void onViewCreated(#NonNull View view, #Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
tts = new TextToSpeech(getActivity(), this);
speakButton = view.findViewById(R.id.speakButton);
speechText = view.findViewById(R.id.speechText);
speakButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
speakOut();
}
});
}
private void speakOut(){
String text = speechText.getText().toString();
tts.speak(text, TextToSpeech.QUEUE_FLUSH, null);
}
public void onInit(int status){
if(status == TextToSpeech.SUCCESS){
int result = tts.setLanguage(Locale.getDefault());
if(result == TextToSpeech.LANG_MISSING_DATA || result == TextToSpeech.LANG_NOT_SUPPORTED){
Toast.makeText(getActivity(), "Language not supported!", Toast.LENGTH_SHORT).show();
} else {
speakButton.setEnabled(true);
speakOut();
}
}
else
{
Toast.makeText(getActivity(), "Initilization failed!", Toast.LENGTH_SHORT).show();
}
}
public void onDestroy() {
if(tts != null){
tts.stop();
tts.shutdown();
}
super.onDestroy();
}
}

Animation for activity(intent)

my promblem is : i cant use animition for intent becuse this calss extend recyclerView adapter i know overridePendingTransition();but its dont work for tis class
It does not know => overridePendingTransition(R.layout.one,R.layout.two);
public class ListAdapterw extends RecyclerView.Adapter {
List<cardViewhomeinfo> sliders;
ImageLoader imageLoader=ImageLoader.getInstance();
public ListAdapterw(List<cardViewhomeinfo> sliders) {
this.sliders = sliders;
}
#Override
public Holder onCreateViewHolder(ViewGroup parent, int viewType) {
LayoutInflater inflater=LayoutInflater.from(parent.getContext());
View view=inflater.inflate(R.layout.recycleview_home,parent,false);
return new Holder(view);
}
#Override
public void onBindViewHolder(Holder holder, int position) {
holder.title.setText(sliders.get(position).getTitle());
holder.id=sliders.get(position).getId();
imageLoader.displayImage("http://wwwww"+sliders.get(position).getPicture(),holder.pic);
}
#Override
public int getItemCount() {
return sliders.size();
}
public class Holder extends RecyclerView.ViewHolder{
public TextView title;
public ImageView pic;
public String id="";
CardView cardView;
public Holder(final View itemView) {
super(itemView);
title=(TextView)itemView.findViewById(R.id.TitleCardView_home);
pic=(ImageView)itemView.findViewById(R.id.imageCardView_home);
cardView= (CardView) itemView.findViewById(R.id.cardView);
cardView.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent intent = new Intent(itemView.getContext(),subCat.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.putExtra("id",id);
overridePendingTransition(R.layout.one,R.layout.two);
itemView.getContext().startActivity(intent);
}
});
}
}
}
and my activtity
public class Home extends Fragment {
View view;
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
view= inflater.inflate(R.layout.fragment_home, container, false);
JSON();
return view;
}
private void JSON() {
final RecyclerView recyclerView1 = (RecyclerView) view.findViewById(R.id.recycle_home);
StringRequest request=new StringRequest(Request.Method.GET, "", new Response.Listener<String>() {
#Override
public void onResponse(String s) {
try {
List<cardViewhomeinfo> sliders = new ArrayList<>();
JSONArray jsonArray=new JSONArray(s);
for(int i=0;i<jsonArray.length();i++){
JSONObject jsonObject=jsonArray.getJSONObject(i);
cardViewhomeinfo slider = new cardViewhomeinfo();
slider.setTitle(jsonObject.getString("title"));
slider.setPicture(jsonObject.getString("pic"));
slider.setId(jsonObject.getString("id"));
sliders.add(slider);
}
ListAdapterw adapter = new ListAdapterw(sliders);
recyclerView1.setLayoutManager(new LinearLayoutManager(getActivity().getApplicationContext()));
recyclerView1.setAdapter(adapter);
} catch (JSONException e) {
e.printStackTrace();
}
}
}, new Response.ErrorListener() {
#Override
public void onErrorResponse(VolleyError volleyError) {
dialog();
}
});
Volley.newRequestQueue(getActivity().getApplicationContext()).add(request);
}
private void dialog() {
Toast.makeText(getActivity().getApplicationContext(),"No INTENT",Toast.LENGTH_LONG).show();
}
#Override
public void onViewCreated(View view, #Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
getActivity().setTitle("Home");
}
}
and subActivty
public class subCat extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_sub_cat);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
Intent intent = getIntent();
final String idCat = intent.getStringExtra("id");
Toast.makeText(getApplicationContext(),idCat,Toast.LENGTH_LONG).show();}
Put your overridePendingTransition(R.layout.one,R.layout.two); code into the onCreate of the activity that you're going to when you click on cardView.
It should be something like this in your onCreate method of the activity:
public class subCat extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_sub_cat);
overridePendingTransition(R.layout.one,R.layout.two); //Put it here.
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
Intent intent = getIntent();
final String idCat = intent.getStringExtra("id");
Toast.makeText(getApplicationContext(),idCat,Toast.LENGTH_LONG).show();
}
Remove overridePendingTransition(R.layout.one,R.layout.two); this from the adapter class of your recycler view.
On the other hand,
overridePendingTransition(R.layout.one,R.layout.two);
it should be called
after finish();
or
after startActivity();

Categories

Resources