冲刺第二阶段二
以下是我们团队做的关于学生的几个功能
package com.example.shazidouhuiapp.activity; import android.content.Context; import android.content.Intent; import android.os.Bundle; import android.util.AttributeSet; import android.util.Log; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.LinearLayout; import android.widget.TextView; import android.widget.Toast; import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.appcompat.app.AppCompatActivity; import androidx.fragment.app.Fragment; import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.RecyclerView; import androidx.swiperefreshlayout.widget.SwipeRefreshLayout; import com.example.shazidouhuiapp.Adapter.HomeAdatpter; import com.example.shazidouhuiapp.Adapter.readReceiveAdapter; import com.example.shazidouhuiapp.Adapter.receiveAdapter; import com.example.shazidouhuiapp.Bean.User; import com.example.shazidouhuiapp.Bean.homework; import com.example.shazidouhuiapp.Bean.homeworkContent; import com.example.shazidouhuiapp.R; import java.util.ArrayList; import java.util.List; import cn.bmob.v3.BmobQuery; import cn.bmob.v3.BmobUser; import cn.bmob.v3.datatype.BmobPointer; import cn.bmob.v3.exception.BmobException; import cn.bmob.v3.listener.FindListener; public class student_readover_receive extends AppCompatActivity { private String id; private RecyclerView rv; private SwipeRefreshLayout srlayout; private TextView helloquestion; // private TextView HelloHome; // private TextView username,ok; private LinearLayout homesearch; List<homeworkContent> data; private readReceiveAdapter readreceiveAdapter; @Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.student_unfinished_question); initView(); //初始刷新 Refresh(); srlayout.setColorSchemeResources(android.R.color.holo_green_light,android.R.color.holo_red_light,android.R.color.holo_blue_light); srlayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() { @Override public void onRefresh() { //刷新; Refresh(); } }); } private void Refresh() { Intent a=getIntent(); id=a.getStringExtra("id"); String title=a.getStringExtra("title"); helloquestion.setText(title); homework homework=new homework(); homework.setObjectId(id+""); BmobQuery<homeworkContent> query=new BmobQuery(); query.addWhereRelatedTo("homeworkContent",new BmobPointer(homework)); query.findObjects(new FindListener<homeworkContent>() { @Override public void done(List<homeworkContent> list, BmobException e) { if(e==null){ data=list; readreceiveAdapter =new readReceiveAdapter(student_readover_receive.this,data,id); rv.setLayoutManager(new LinearLayoutManager(student_readover_receive.this)); rv.setAdapter(readreceiveAdapter); } else { Toast.makeText(student_readover_receive.this, "题目数据获取失败", Toast.LENGTH_SHORT).show(); } } }); } private void initView() { rv = findViewById(R.id.question_recyclerview); srlayout =findViewById(R.id.question_swipe); helloquestion=findViewById(R.id.helloquestion); } }
package com.example.shazidouhuiapp.activity; import android.content.Context; import android.content.Intent; import android.os.Bundle; import android.util.AttributeSet; import android.util.Log; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.LinearLayout; import android.widget.TextView; import android.widget.Toast; import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.appcompat.app.AppCompatActivity; import androidx.fragment.app.Fragment; import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.RecyclerView; import androidx.swiperefreshlayout.widget.SwipeRefreshLayout; import com.example.shazidouhuiapp.Adapter.HomeAdatpter; import com.example.shazidouhuiapp.Adapter.receiveAdapter; import com.example.shazidouhuiapp.Bean.User; import com.example.shazidouhuiapp.Bean.homework; import com.example.shazidouhuiapp.Bean.homeworkContent; import com.example.shazidouhuiapp.R; import java.util.ArrayList; import java.util.List; import cn.bmob.v3.BmobQuery; import cn.bmob.v3.BmobUser; import cn.bmob.v3.datatype.BmobPointer; import cn.bmob.v3.exception.BmobException; import cn.bmob.v3.listener.FindListener; public class student_unfinished_receive extends AppCompatActivity { private String id; private RecyclerView rv; private SwipeRefreshLayout srlayout; private TextView helloquestion; // private TextView HelloHome; // private TextView username,ok; private LinearLayout homesearch; List<homeworkContent> data; private receiveAdapter receiveAdapter; @Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.student_unfinished_question); initView(); //初始刷新 Refresh(); srlayout.setColorSchemeResources(android.R.color.holo_green_light,android.R.color.holo_red_light,android.R.color.holo_blue_light); srlayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() { @Override public void onRefresh() { //刷新; Refresh(); } }); } private void Refresh() { Intent a=getIntent(); id=a.getStringExtra("id"); String title=a.getStringExtra("title"); helloquestion.setText(title+""); homework homework=new homework(); homework.setObjectId(id+""); BmobQuery<homeworkContent> query=new BmobQuery(); query.addWhereRelatedTo("homeworkContent",new BmobPointer(homework)); query.findObjects(new FindListener<homeworkContent>() { @Override public void done(List<homeworkContent> list, BmobException e) { if(e==null){ data=list; receiveAdapter =new receiveAdapter(student_unfinished_receive.this,data,id); rv.setLayoutManager(new LinearLayoutManager(student_unfinished_receive.this)); rv.setAdapter(receiveAdapter); } else { Toast.makeText(student_unfinished_receive.this, "题目数据获取失败", Toast.LENGTH_SHORT).show(); } } }); } private void initView() { rv = findViewById(R.id.question_recyclerview); srlayout =findViewById(R.id.question_swipe); helloquestion=findViewById(R.id.helloquestion); } }
package com.example.shazidouhuiapp.activity; import android.content.Intent; import android.os.Bundle; import android.util.Log; import android.view.View; import android.widget.Button; import android.widget.EditText; import android.widget.ImageView; import android.widget.TextView; import android.widget.Toast; import androidx.annotation.Nullable; import androidx.appcompat.app.AppCompatActivity; import androidx.recyclerview.widget.LinearLayoutManager; import com.example.shazidouhuiapp.Adapter.receiveAdapter; import com.example.shazidouhuiapp.Bean.homework; import com.example.shazidouhuiapp.Bean.homeworkContent; import com.example.shazidouhuiapp.R; import java.util.List; import cn.bmob.v3.BmobQuery; import cn.bmob.v3.datatype.BmobPointer; import cn.bmob.v3.exception.BmobException; import cn.bmob.v3.listener.FindListener; import cn.bmob.v3.listener.QueryListener; import cn.bmob.v3.listener.UpdateListener; public class student_unfinished_receive_question extends AppCompatActivity { private TextView question,score,status; private EditText myanswer; private Button submit; private ImageView returnview; private String id,parent; private homeworkContent hom; private homework homework; @Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.student_unfinished_recieve); initview(); initdata(); returnview.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { finish(); } }); } private void initdata() { //另外一种 Intent a=getIntent(); id=a.getStringExtra("id"); parent=a.getStringExtra("parentid"); hom=new homeworkContent(); homework=new homework(); hom.setObjectId(id+""); homework.setObjectId(parent+""); String mquestion=a.getStringExtra("question"); String mscore=a.getStringExtra("score"); String mstatus=a.getStringExtra("status"); if(mstatus.equals("true")){ status.setText("已完成"); } else if(mstatus.equals("false")){ status.setText("未完成"); } question.setText(mquestion); score.setText(mscore); submit.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { final String answer=myanswer.getText().toString().trim(); if(answer.isEmpty()){ Toast.makeText(student_unfinished_receive_question.this, "请输入你的答案", Toast.LENGTH_SHORT).show(); } else { hom.setMyAnswer(answer); hom.setStatus(true); hom.update(new UpdateListener() { @Override public void done(BmobException e) { if(e==null){ BmobQuery<homeworkContent> query=new BmobQuery(); query.addWhereRelatedTo("homeworkContent",new BmobPointer(homework)); query.findObjects(new FindListener<homeworkContent>() { @Override public void done(List<homeworkContent> list, BmobException e) { if(e==null){ int flag=0; for (homeworkContent homew:list ) { if(homew.isStatus()==true){ flag++; } } Toast.makeText(student_unfinished_receive_question.this, "本小题提交成功", Toast.LENGTH_SHORT).show(); if(flag>=(list.size()-1)){ homework.setStatus(true); homework.update(new UpdateListener() { @Override public void done(BmobException e) { if(e==null){ Toast.makeText(student_unfinished_receive_question.this, "您已完成本次作业所有题目", Toast.LENGTH_SHORT).show(); } else { Toast.makeText(student_unfinished_receive_question.this, "本次作业更新失败"+e.getMessage(), Toast.LENGTH_SHORT).show(); } } }); } } else { Toast.makeText(student_unfinished_receive_question.this, "获取题目数据失败", Toast.LENGTH_SHORT).show(); } } }); } else{ Log.d("提交失败", e.getMessage()+""); Toast.makeText(student_unfinished_receive_question.this, "提交失败"+e.getMessage(), Toast.LENGTH_LONG).show(); } } }); } } }); } private void initview() { question=findViewById(R.id.receive_question_question); score=findViewById(R.id.receive_question_score); status=findViewById(R.id.receive_question_status); myanswer=findViewById(R.id.receive_myanswer); returnview=findViewById(R.id.receiveback); submit=findViewById(R.id.receive_submit); } }
package com.example.shazidouhuiapp.activity; import android.os.Bundle; import android.widget.TextView; import androidx.annotation.Nullable; import androidx.appcompat.app.AppCompatActivity; import androidx.fragment.app.Fragment; import androidx.viewpager.widget.ViewPager; import com.ashokvarma.bottomnavigation.BottomNavigationBar; import com.ashokvarma.bottomnavigation.BottomNavigationItem; import com.example.shazidouhuiapp.Adapter.setAdapter; import com.example.shazidouhuiapp.R; import com.example.shazidouhuiapp.fragment.FragmentMine; import com.example.shazidouhuiapp.fragment.FragmentReadOver; import com.example.shazidouhuiapp.fragment.FragmentUnfinished; import java.util.ArrayList; import java.util.List; public class studentinterface extends AppCompatActivity implements BottomNavigationBar.OnTabSelectedListener, ViewPager.OnPageChangeListener { private ViewPager viewPager; private BottomNavigationBar bottomNavigationBar; private List<Fragment> fragmentList; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); viewPager=findViewById(R.id.viewpager); bottomNavigationBar=findViewById(R.id.bottom); initView(); } private void initView() { initViewPager(); initBottom(); } private void initBottom() { bottomNavigationBar.setTabSelectedListener(this); bottomNavigationBar.clearAll(); bottomNavigationBar.setMode(BottomNavigationBar.MODE_FIXED); bottomNavigationBar.setBackgroundStyle(BottomNavigationBar.BACKGROUND_STYLE_DEFAULT); bottomNavigationBar.setBarBackgroundColor(R.color.white).setActiveColor(R.color.colorbasel) .setInActiveColor(R.color.black); bottomNavigationBar.addItem(new BottomNavigationItem(R.drawable.homepage_fill,"未完成作业").setInactiveIconResource(R.drawable.homepage)) .addItem(new BottomNavigationItem(R.drawable.mobilephone_fill,"已批改作业").setInactiveIconResource(R.drawable.mobilephone)) .addItem(new BottomNavigationItem(R.drawable.mine_fill,"我的").setInactiveIconResource(R.drawable.mine)) .setFirstSelectedPosition(0) .initialise(); } private void initViewPager() { viewPager.setOffscreenPageLimit(3); //配置fragment fragmentList=new ArrayList<>(); //三个底部导航栏的实例化 fragmentList.add(new FragmentUnfinished()); fragmentList.add(new FragmentReadOver()); fragmentList.add(new FragmentMine()); viewPager.setAdapter(new setAdapter(getSupportFragmentManager(),fragmentList)); viewPager.addOnPageChangeListener(this); viewPager.setCurrentItem(0); } @Override public void onTabSelected(int position) { } @Override public void onTabUnselected(int position) { } @Override public void onTabReselected(int position) { viewPager.setCurrentItem(position); } @Override public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) { } @Override public void onPageSelected(int position) { bottomNavigationBar.selectTab(position); } @Override public void onPageScrollStateChanged(int state) { } }