 
设计作业系统，实现左右滑动切换界面，也可以点击不同的按钮切换对应的界面，要求界面要美观，实现以下功能： 
(1) 使用Fragment、ViewPager配合显示“列表”界面，“记作业”页面，“分析”页面，“我的”界面；
(3) 使用RecyclerView显示作业列表，点击能看到作业详情，并能回退到列表界面；
(3) 设计记作业页面，包括：日期、作业类型（语文或数学等）、作业内容，备注；
(4) 分析页面放图表；
(5) 我的界面，显示个人信息；
(6) 界面设计要友好并美观。
ADDHOMEWORKFRAGMENT//
public class AddHomeworkFragment extends Fragment {


    private static final String ARG_PARAM1 = "param1";
    private static final String ARG_PARAM2 = "param2";


    private String mParam1;
    private String mParam2;

    public AddHomeworkFragment() {

    }


    public static AddHomeworkFragment newInstance(String param1, String param2) {
        AddHomeworkFragment fragment = new AddHomeworkFragment();
        Bundle args = new Bundle();
        args.putString(ARG_PARAM1, param1);
        args.putString(ARG_PARAM2, param2);
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (getArguments() != null) {
            mParam1 = getArguments().getString(ARG_PARAM1);
            mParam2 = getArguments().getString(ARG_PARAM2);
        }
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_add_homework, container, false);

        EditText dateEdit = view.findViewById(R.id.dateEdit);
        EditText typeEdit = view.findViewById(R.id.typeEdit);
        EditText contentEdit = view.findViewById(R.id.contentEdit);
        EditText remarkEdit = view.findViewById(R.id.remarkEdit);
        Button saveBtn = view.findViewById(R.id.saveBtn);

        saveBtn.setOnClickListener(v->{
            Homework.dataList.add(new Homework(
                    dateEdit.getText().toString(),
                    typeEdit.getText().toString(),
                    contentEdit.getText().toString(),
                    remarkEdit.getText().toString()));
        });


        return view;
    }
}


analysisfragment//
public class AnalysisFragment extends Fragment {

    private static final String ARG_PARAM1 = "param1";
    private static final String ARG_PARAM2 = "param2";

    private String mParam1;
    private String mParam2;

    public AnalysisFragment() {

    }


    public static AnalysisFragment newInstance(String param1, String param2) {
        AnalysisFragment fragment = new AnalysisFragment();
        Bundle args = new Bundle();
        args.putString(ARG_PARAM1, param1);
        args.putString(ARG_PARAM2, param2);
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (getArguments() != null) {
            mParam1 = getArguments().getString(ARG_PARAM1);
            mParam2 = getArguments().getString(ARG_PARAM2);
        }
    }

    LinearLayout chartArea;
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        View view = inflater.inflate(R.layout.fragment_analysis, container, false);

        chartArea = view.findViewById(R.id.chartArea);

        return view;
    }

    @Override
    public void onResume() {
        super.onResume();

        String[] types = {"语文", "数学", "英语"};
        int[] counts = new int[3];

        for(Homework hw : Homework.dataList) {
            if(hw.type.equals("语文")) {
                ++counts[0];
            } else if(hw.type.equals("数学")) {
                ++counts[1];
            } else {
                ++counts[2];
            }
        }

        for(int i = 0; i < 3; ++i) {
            LinearLayout layout = new LinearLayout(getContext());

            TextView tv = new TextView(getContext());
            tv.setText(types[i] + "\n" + counts[i]);
            layout.addView(tv);

            View bar = new View(getContext());
            bar.setBackgroundColor(0xff888888);
            layout.addView(bar, new LinearLayout.LayoutParams(60, 120 * counts[i]));

            chartArea.addView(layout);
        }
    }
}


homework//
public class Homework implements Serializable {
    public static List<Homework> dataList = new ArrayList<>();

    String date;
    String type;
    String content;
    String remark;

    Homework(String date, String type, String content, String remark) {
        this.date = date;
        this.type = type;
        this.content = content;
        this.remark = remark;
    }
}


HOMEWORKDETAILACTIVITY//
public class HomeworkDetailActivity extends AppCompatActivity {

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

        TextView dateTV = findViewById(R.id.dateTV);
        TextView typeTV = findViewById(R.id.typeTV);
        TextView contentTV = findViewById(R.id.contentTV);
        TextView remarkTV = findViewById(R.id.remarkTV);

        Homework hw = (Homework)getIntent().getSerializableExtra("Homework");
        dateTV.setText(hw.date);
        typeTV.setText(hw.type);
        contentTV.setText(hw.content);
        remarkTV.setText(hw.remark);
    }
}


MAINactivity
public class MainActivity extends AppCompatActivity {

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

    
        ViewPager2 viewPager = findViewById(R.id.viewPager);
        viewPager.setAdapter(new ViewPagerAdapter(this));

        Button listBtn = findViewById(R.id.listBtn);
        Button addBtn = findViewById(R.id.addBtn);
        Button analysisBtn = findViewById(R.id.analysisBtn);
        Button myBtn = findViewById(R.id.myBtn);

        listBtn.setOnClickListener(v->{
            viewPager.setCurrentItem(0);
        });
        addBtn.setOnClickListener(v->{
            viewPager.setCurrentItem(1);
        });
        analysisBtn.setOnClickListener(v->{
            viewPager.setCurrentItem(2);
        });
        myBtn.setOnClickListener(v->{
            viewPager.setCurrentItem(3);
        });
    }

    class ViewPagerAdapter extends FragmentStateAdapter{
        ViewPagerAdapter(AppCompatActivity context) {
            super(context);
        }

        @NonNull
        @Override
        public Fragment createFragment(int position) {
            switch (position) {
                case 0:
                    return new ShowHomeworkFragment();
                case 1:
                    return new AddHomeworkFragment();
                case 2:
                    return new AnalysisFragment();
                case 3:
                    return new MyFragment();
            }
            return null;
        }

        @Override
        public int getItemCount() {
            return 4;
        }
    }

}

Myfragment//
public class MyFragment extends Fragment {


    private static final String ARG_PARAM1 = "param1";
    private static final String ARG_PARAM2 = "param2";

    private String mParam1;
    private String mParam2;

    public MyFragment() {
        // Required empty public constructor
    }

    public static MyFragment newInstance(String param1, String param2) {
        MyFragment fragment = new MyFragment();
        Bundle args = new Bundle();
        args.putString(ARG_PARAM1, param1);
        args.putString(ARG_PARAM2, param2);
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (getArguments() != null) {
            mParam1 = getArguments().getString(ARG_PARAM1);
            mParam2 = getArguments().getString(ARG_PARAM2);
        }
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        return inflater.inflate(R.layout.fragment_my, container, false);
    }
}


showhomeworkfragment//

public class ShowHomeworkFragment extends Fragment {


    private static final String ARG_PARAM1 = "param1";
    private static final String ARG_PARAM2 = "param2";


    private String mParam1;
    private String mParam2;

    public ShowHomeworkFragment() {
       
    }


    public static ShowHomeworkFragment newInstance(String param1, String param2) {
        ShowHomeworkFragment fragment = new ShowHomeworkFragment();
        Bundle args = new Bundle();
        args.putString(ARG_PARAM1, param1);
        args.putString(ARG_PARAM2, param2);
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (getArguments() != null) {
            mParam1 = getArguments().getString(ARG_PARAM1);
            mParam2 = getArguments().getString(ARG_PARAM2);
        }
    }

    HomeworkAdapter adapter;
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        View view = inflater.inflate(R.layout.fragment_show_homework, container, false);

        RecyclerView recyclerView = view.findViewById(R.id.recycleView);
        recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
        adapter = new HomeworkAdapter();
        recyclerView.setAdapter(adapter);

        return view;
    }

    @Override
    public void onResume() {
        super.onResume();
        adapter.notifyDataSetChanged();
    }

    public class HomeworkAdapter extends RecyclerView.Adapter<HomeworkAdapter.VH> {
        class VH extends RecyclerView.ViewHolder{
            TextView tv;
            VH(TextView tv) {
                super(tv);
                this.tv = tv;
                tv.setOnClickListener(v->{
                    Intent it = new Intent(getContext(), HomeworkDetailActivity.class);
                    it.putExtra("Homework", Homework.dataList.get(getAdapterPosition()));
                    startActivity(it);
                });
            }
        }

        @NonNull
        @Override
        public VH onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
            return new VH(new TextView(getContext()));
        }

        @Override
        public void onBindViewHolder(@NonNull VH holder, int position) {
            holder.tv.setText("作业" + position);
        }

        @Override
        public int getItemCount() {
            return Homework.dataList.size();
        }
    }
}


1. 编写一个程序，实现记录备忘录功能，列出所有内部或外部的所有txt文件，将文件名称显示到ListView控件上，点击某个文件，转到详细页面显示，长按某个文件能实现删除。并能新建备忘录，将写好的备忘录保存到设备内部或外部中。


ADDacitivty//
       public class AddActivity extends AppCompatActivity {

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

        EditText nameEdit = findViewById(R.id.nameEdit);
        EditText contentEdit = findViewById(R.id.contentEdit);
        Button saveBtn = findViewById(R.id.saveBtn);

        saveBtn.setOnClickListener(v->{
            try {
                String fileName = nameEdit.getText().toString();
                String content = contentEdit.getText().toString();
                FileWriter w = new FileWriter(new File(getFilesDir(),fileName+ ".txt"));
                w.write(content);
                w.close();
                finish();
            } catch (Exception e) {
            }
        });
    }
}

DETAILactivity
public class DetailActivity extends AppCompatActivity {

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


        TextView nameView = findViewById(R.id.nameView);
        TextView contentView = findViewById(R.id.contentView);
        Button backBtn = findViewById(R.id.backBtn);

        String fileName = getIntent().getStringExtra("fileName");
        String filePath = getIntent().getStringExtra("filePath");
        String content = "";
        try {
            Scanner s = new Scanner(new File(filePath));
            s.useDelimiter("\\A");
            if(s.hasNext())
                content = s.next();
        } catch (Exception e) {
        }

        nameView.setText(fileName);
        contentView.setText(content);


        backBtn.setOnClickListener(v->finish());
    }
}

mainactivity//
public class MainActivity extends AppCompatActivity {


    ArrayList<String> fileNames, filePaths;
    ArrayAdapter<String> adapter;

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



        fileNames = new ArrayList<>();
        filePaths = new ArrayList<>();

        ListView listView = findViewById(R.id.listView);
        Button addBtn = findViewById(R.id.addBtn);

        adapter = new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, fileNames);
        listView.setAdapter(adapter);

     
        addBtn.setOnClickListener(v->{
            Intent it = new Intent(this, AddActivity.class);
            startActivity(it);
        });

      
        listView.setOnItemClickListener((p, v, pos, id)->{
            Intent it = new Intent(this, DetailActivity.class);
            it.putExtra("fileName", fileNames.get(pos));
            it.putExtra("filePath", filePaths.get(pos));
            startActivity(it);
        });
     
        listView.setOnItemLongClickListener((p, v, pos, id)->{
            File file = new File(filePaths.get(pos));
            file.delete();
            fileNames.remove(pos);
            filePaths.remove(pos);
            adapter.notifyDataSetChanged();
            return true;
        });
    }

    @Override
    protected void onResume() {
        super.onResume();
        loadFile();
    }

    void loadFile()
    {
     
        fileNames.clear();
        filePaths.clear();
    
        scanDir(getFilesDir());
    
        scanDir(getExternalFilesDir(null));

        adapter.notifyDataSetChanged();
    }

    void scanDir(File dir)
    {
        File[] files = dir.listFiles();
        for(File file : files)
        {
            if(file.isFile() && file.getName().endsWith(".txt")) {
                fileNames.add(file.getName());
                filePaths.add(file.getAbsolutePath());
            } else if(file.isDirectory()) {
                scanDir(file);
            }
        }
    }



}

2. 编写一个程序，实现登录功能，在登录界面中包含一个复选按钮“Remember me”，选择时保存用户名和密码，否则只保存用户名，打开登录界面时，如果有保存的信息，则将保存的信息显示到对应控件中。
mainactivity//
public class MainActivity extends AppCompatActivity {

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


        EditText uEdit = findViewById(R.id.uEdit);
        EditText pEdit = findViewById(R.id.pEdit);
        CheckBox rememberCheck = findViewById(R.id.rememberCheck);
        Button loginBtn = findViewById(R.id.loginBtn);

        SharedPreferences sp = getSharedPreferences("login", MODE_PRIVATE);

        uEdit.setText(sp.getString("u", ""));
        pEdit.setText(sp.getString("p", ""));


        loginBtn.setOnClickListener(v->{
            String u = uEdit.getText().toString();
            String p = pEdit.getText().toString();
            sp.edit()
                    .putString("u", u)
                    .putString("p", rememberCheck.isChecked() ? p : "")
                    .apply();

            Toast.makeText(this, "登录成功", Toast.LENGTH_SHORT).show();
        });

    }
}

