TextView with data from firebase rt dababase disappear on screen - 2nd qustion

这一生的挚爱 提交于 2020-01-05 04:27:08

问题


I'm trying to get a user name from the database and set it as text on the screen. I have 3 Activity and Fragment objects.

I'm trying to get name of the user in main activity:

The first activity is a login activity that have user sign in and sign up functions with firebase auth integration.

After that , if sign in or sign up success , Splash activity is open. in splash activity , i should get user display name ().

In the () function i'm creating a new user object and setting the display name.

after 3 seconds , Splash activity is closed and main activity is open. in main activity i'm calling to user.getDisplayName.

Splash activity:

public void getDataFromUsersDetails() {
        ValueEventListener eventListener = new ValueEventListener() {
            @Override
            public void onDataChange(DataSnapshot dataSnapshot) {
                for (DataSnapshot ds : dataSnapshot.getChildren()) {
                    mDisplayName = ds.child(mAuth.getCurrentUser().getUid()).child("mEventOwnerName").getValue(String.class);
                    user = new User();
                    user.setmDisplayName(mDisplayName);
                }
            }
        users.addListenerForSingleValueEvent(eventListener);
    }
User class:
public String setGreetingsOnTop(){
        return getmDisplayName();
    }
MainActivity:
@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        user = new User();


        mWelcomeText = findViewById(R.id.mWelcomeText);
        mWelcomeText.setText(user.getmDisplayName());
        mWelcomeText.setText(user.setGreetingsOnTop());
    }

I want the text to be displayed on the screen, in the field of private TextView mWelcomeText.

In the layout_main I can see the text view with the tool:text="something"; But when I am running it on a real device or an emulator, just an empty place appears.

来源:https://stackoverflow.com/questions/57904790/textview-with-data-from-firebase-rt-dababase-disappear-on-screen-2nd-qustion

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!