Newer
Older
NemophilaClient / app / src / main / java / com / example / nemophila / MyPageActivity.java
k-suzuki on 22 Jun 2023 3 KB MyPageActivityを作った
package com.example.nemophila;

import androidx.appcompat.app.AppCompatActivity;
import androidx.lifecycle.Observer;
import androidx.lifecycle.ViewModelProvider;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import com.example.nemophila.FriendActivity;
import com.example.nemophila.MainActivity;
import com.example.nemophila.MyPageEditorActivity;
import com.example.nemophila.R;
import com.example.nemophila.RequestedActivity;
import com.example.nemophila.entities.Account;
import com.example.nemophila.entities.Post;
import com.example.nemophila.viewmodels.AccountViewModel;

import java.util.List;

public class MyPageActivity extends AppCompatActivity {
//MyPageActivity画面の作成
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_mypage);

        Nemophila nemophila = (Nemophila) getApplication();

//ボタンを押した場合の画面遷移
        Button friendButton = (Button) findViewById(R.id.friend);
        friendButton.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                Intent intent = new Intent(MyPageActivity.this, FriendActivity.class);
                startActivity(intent);

            }
        });
        Button changeMyPageButton = (Button) findViewById(R.id.changeMyPage);
        changeMyPageButton.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                Intent intent = new Intent(MyPageActivity.this, MyPageEditorActivity.class);
                startActivity(intent);
            }

        });

        Button cancelButton = (Button) findViewById(R.id.cancel);
        cancelButton.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                Intent intent = new Intent(MyPageActivity.this, MainActivity.class);
                startActivity(intent);
            }
        });
        Button RequestedButton = (Button) findViewById(R.id.requested);
        RequestedButton.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                Intent intent = new Intent(MyPageActivity.this, RequestedActivity.class);
                startActivity(intent);
            }
        });
//AccountViewModelとの通信とテキストの表示
        AccountViewModel accountViewModel = new ViewModelProvider(this).get(AccountViewModel.class);
        accountViewModel.getAccountLiveData().observe(this, new Observer <Account>() {
            @Override
            public void onChanged(Account account) {
                String name = account.getName();
                TextView myName = (TextView) findViewById(R.id.name);
                myName.setText(name);
                nemophila.setName(name);
            }

        });
        String uid = nemophila.getUid();
        String name = nemophila.getName();
        TextView myName = (TextView) findViewById(R.id.name);
        myName.setText(name);
        TextView id = (TextView) findViewById(R.id.id);
        id.setText(uid);

    }
}