【问题标题】:How to pass information to a navigation header in Android Studio如何将信息传递给 Android Studio 中的导航标头
【发布时间】:2019-06-16 11:30:34
【问题描述】:

我有一个向用户询问信息的活动,AskUserForDetailsActivity,我还有另一个 TabActivity(不是紧跟在 AskUser.. 活动之后),它有一个导航抽屉。

我想将来自 AskUser.. 的信息发送到抽屉的导航标题,它又在另一个布局中。

我试过了:

 sendButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent intent = new Intent(getApplicationContext(), TabActivity.class);
            intent.putExtra("Name", textView1.getText().toString());
            intent.putExtra("Age", textView2.getText().toString());
            intent.putExtra("Area", textView3.getText().toString());
            intent.putExtra("Occupation", textView4.getText().toString());
        }
    });

这来自 AskForUser.. 这在 TabActivity 中进行:

 View v = getLayoutInflater().inflate(R.layout.nav_header_navigation,null);
    TextView receive1 = (TextView) v.findViewById(R.id.myName);
    receive1.setText(getIntent().getStringExtra("Name"));
    TextView receive2 = (TextView) v.findViewById(R.id.myAge);
    receive2.setText(getIntent().getStringExtra("Age"));
    TextView receive3 = (TextView) v.findViewById(R.id.myArea);
    receive3.setText(getIntent().getStringExtra("Area"));
    TextView receive4 = (TextView) v.findViewById(R.id.myOccupation);
    receive4.setText(getIntent().getStringExtra("Occupation"));

但文本没有出现在我的导航标题中。我做错了什么?

【问题讨论】:

    标签: android navigation-drawer message-passing


    【解决方案1】:

    代替:

    View v = getLayoutInflater().inflate(R.layout.nav_header_navigation,null);
    

    你能试试下面的代码吗

    NavigationView navigationView = findViewById(R.id.nav_view);
    View v = navigationView.getHeaderView(0);
    

    【讨论】:

    • 不,仍然没有输出。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多