0

現在のユーザー名をアプリのスライド メニューの先頭に追加しようとしています。

~ネットで拾ってきた画像と同じ~

このコードを追加しようとしましたが、エラーが発生します:

ParseUser.getCurrentUser();
t_username = (TextView) findViewById(R.id.username);
t_username.setText(user.getUsername());

これはスライド メニューのコードです。

package com.androidbegin.parselogintutorial;

import android.content.Intent;
import android.os.Bundle;
import android.support.design.widget.NavigationView;
import android.support.v4.view.GravityCompat;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBarDrawerToggle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.ImageButton;
import android.widget.ProgressBar;
import android.widget.TextView;
import com.parse.ParseUser;
import static com.androidbegin.parselogintutorial.R.drawable.user;
import static com.androidbegin.parselogintutorial.R.id.nav_camera;

public class SlidingMenu extends AppCompatActivity
        implements NavigationView.OnNavigationItemSelectedListener {


    ImageButton lectureNotes, labNotes, quizzes, mt;
    TextView t_username;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_sliging_menu);
        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);

        ParseUser.getCurrentUser();
        t_username = (TextView) findViewById(R.id.username);
        ParseUser.getCurrentUser();
        t_username.setText(user.getUsername());

        final ProgressBar simpleProgressBar = (ProgressBar) findViewById(R.id.simpleProgressBar);
        simpleProgressBar.setVisibility(View.INVISIBLE);

        DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
        ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
                this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
        drawer.setDrawerListener(toggle);
        toggle.syncState();

        NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);

        .
        .
        .

        navigationView.setNavigationItemSelectedListener(this);

    @Override
    public void onBackPressed() {
        DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
        if (drawer.isDrawerOpen(GravityCompat.START)) {
            drawer.closeDrawer(GravityCompat.START);
        } else {
            super.onBackPressed();
        }
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.sliging_menu, menu);
        return true;


    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();

        //noinspection SimplifiableIfStatement
        if (id == R.id.action_settings) {
            return true;
        }

        return super.onOptionsItemSelected(item);
    }

        .
        .
        .

        DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
        drawer.closeDrawer(GravityCompat.START);
        return true;

    }


}

これは、ナビゲーション ヘッダーのレイアウトです。

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="@dimen/nav_header_height"
    android:background="@drawable/side_nav_bar"
    android:gravity="bottom"
    android:orientation="vertical"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:theme="@style/ThemeOverlay.AppCompat.Dark">


    <ImageView
        android:layout_width="30dp"
        android:layout_height="60dp"
        android:layout_marginLeft="3dp"
        android:paddingTop="@dimen/nav_header_vertical_spacing"
        app:srcCompat="@drawable/user"
        android:scaleType="fitEnd"
        android:id="@+id/imageView3" />

    <TextView
        android:layout_width="match_parent"
        android:id="@+id/username"
        android:layout_height="wrap_content"
        android:layout_marginLeft="10dp"
        android:layout_marginBottom="10dp"
        android:textColor="#fff"
        android:paddingTop="@dimen/nav_header_vertical_spacing"
        android:textAppearance="@style/TextAppearance.AppCompat.Body1"
        android:layout_alignBottom="@+id/imageView3"
        android:layout_toRightOf="@+id/imageView3"
        android:layout_toEndOf="@+id/imageView3" />


</RelativeLayout>

Parse からデータを取得するための正しいコードは何ですか?

4

0 に答える 0