In my adnroid app when the user goes to their own profile, there is a fragment there with two buttons - X points and settings. For the button X points I want to change the text to whatever the amount of points they have, for example 12 points.
I've tried numerous things but nothing seems to work:
Attempt 1:
myProfileActionButtonsHolder = (TableRow) findViewById(R.id.myProfileActionButtonsHolder);
getSupportFragmentManager().beginTransaction().replace(R.id.myProfileActionButtonsHolder, new MyProfileActionButtonsFragment()).commit();
MyProfileActionButtonsFragment.bMyProfilePoints = (Button) findViewById(R.id.bMyProfilePoints);
MyProfileActionButtonsFragment.bMyProfilePoints.setText("asd");
Attempt 2:
MyProfileActionButtonsFragment myProfileActionButtonsFragment = (MyProfileActionButtonsFragment) getSupportFragmentManager().findFragmentById(R.id.myProfileActionButtonsHolder);
((Button)myProfileActionButtonsFragment.getView().findViewById(R.id.bMyProfileSettings)).setText("asd");
Attempt 3
myProfileActionButtonsFragment.setBMyProfileSettingsText("asd"); //setBMyProfileSettingsText is a custom method defined inside the fragment
Here is how my fragment looks:
public class MyProfileActionButtonsFragment extends SherlockFragment {
public static Button bMyProfilePoints;
public Button bMyProfileSettings;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view= inflater.inflate(R.layout.my_profile_action_buttons_fragment, container, false);
bMyProfilePoints = (Button) view.findViewById(R.id.bMyProfilePoints);
bMyProfileSettings = (Button) view.findViewById(R.id.bMyProfileSettings);
return view;
}
public void setBMyProfileSettingsText(String text) {
bMyProfilePoints.setText(text);
}
}
Im ALWAYS getting a NullPointerException on the line where I try to set the text to the button.