My requirement is to load a fragment when I click the ClickableSpan.
I get the error Variable "inflater" is accessed within the inner class, needs to be declared final.
BTW I've created a Tabbed Activity with Action Bar tabs, where I've two tabs with two different fragments(Fragment A and Fragment B in the two tabs) and Fragment C. When I click the ClickableSpan from Fragment A, It should navigate me to fragment
public static class PlaceholderFragment extends Fragment {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View rootView = null;
switch (getArguments().getInt(ARG_SECTION_NUMBER)) {
case 1:
rootView = inflater.inflate(R.layout.fragment_customer, container, false);
TextView register = rootView.findViewById(R.id.customer_register);
String register_text = "You are not a member? Register";
SpannableString spanableObject = new SpannableString(register_text);
ClickableSpan clickableSpan = new ClickableSpan() {
@Override
public void onClick(View widget) {
Toast.makeText(getActivity(), "Clicked", Toast.LENGTH_SHORT).show();
rootView = inflater.inflate(R.layout.fragment_sign_up, container, false);
}
@Override
public void updateDrawState(TextPaint ds) {
super.updateDrawState(ds);
ds.setColor(Color.BLUE);
}
};
spanableObject.setSpan(clickableSpan, 22, 30, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
register.setText(spanableObject);
register.setMovementMethod(LinkMovementMethod.getInstance());
break;
case 2:
rootView = inflater.inflate(R.layout.fragment_contractor, container, false);
break;
}
}
Kindly help me resolve this issue. Million thanks in advance!!