5.7

与小组成员继续讨论如何完成作业的侧边栏以及其他部分,并且完成了该类中的所有应用

代码行量:143行

学习所花时间:1h

 

 

package com.example.memosystem.activity;

import androidx.annotation.NonNull;
import androidx.appcompat.app.ActionBarDrawerToggle;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;
import androidx.core.view.GravityCompat;
import androidx.drawerlayout.widget.DrawerLayout;

import android.content.Intent;
import android.os.Bundle;
import android.view.MenuItem;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.Button;
import android.widget.ListView;

import com.example.memosystem.MainActivity;
import com.example.memosystem.R;
import com.example.memosystem.adapter.RecordAdapter;
import com.example.memosystem.bean.Record;
import com.example.memosystem.dao.AdminDao;
import com.google.android.material.floatingactionbutton.FloatingActionButton;
import com.google.android.material.navigation.NavigationView;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

public class ManageActivity extends AppCompatActivity {


//侧边栏的内容部分

private ListView listView;

List<Record> originalItems;

RecordAdapter adapter;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_manage);

Intent intent=getIntent();
String account=intent.getStringExtra("account");


Button button = findViewById(R.id.button);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent();
intent.setClass(ManageActivity.this, zhuyemian.class);
startActivity(intent);
}
});
//退出的功能
NavigationView navigationView=findViewById(R.id.navigation_view);//引入侧边栏
navigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {
@Override
public boolean onNavigationItemSelected(@NonNull MenuItem item) {
int id=item.getItemId();
if(id==R.id.menu_to_exit){
finishAffinity();//退出功能
}
if(id==R.id.menu_to_login){
Intent intent=new Intent(ManageActivity.this, MainActivity.class);
startActivity(intent);

}

if(id==R.id.menu_up_pwd){
Intent intent=new Intent(ManageActivity.this, ChangePwdActivity.class);
intent.putExtra("account",account);
startActivity(intent);
}

if(id==R.id.menu_mes){
Intent intent=new Intent(ManageActivity.this, MesActivity.class);
intent.putExtra("account",account);
startActivity(intent);
}

return true;
}
});



//添加事件的点击按钮



FloatingActionButton floatingActionButton=findViewById(R.id.fab);
floatingActionButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent=new Intent(ManageActivity.this, AddActivity.class);
intent.putExtra("account",account);
startActivity(intent);
}
});


//现在开发加载列表
listView= findViewById(R.id.manage_list);
//这个列表要从哪里读取数据
originalItems=new ArrayList<>();
//读取数据
originalItems= new AdminDao().showRecord(account);
if(originalItems.size()==0){
listView.setAdapter(null);//让界面啥都不显示
}else{

adapter = new RecordAdapter(this, originalItems);
listView.setAdapter(adapter);
}

Toolbar toolbar= findViewById(R.id.toolbar_man);
this.setSupportActionBar(toolbar);
//返回功能
DrawerLayout drawerLayout =findViewById(R.id.drawer);
toolbar.setNavigationOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
drawerLayout.openDrawer(GravityCompat.START);
}
});







//originalItems=new ArrayList<>();

}
}
posted @ 2024-06-11 09:00  不如喝点  阅读(22)  评论(0编辑  收藏  举报