1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
package safeluck.drive.evaluation.fragment;
 
import android.os.Bundle;
 
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.lifecycle.Observer;
import androidx.lifecycle.ViewModelProviders;
 
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ListView;
 
import java.util.ArrayList;
import java.util.List;
 
import me.yokeyword.fragmentation.SupportFragment;
import safeluck.drive.evaluation.DB.Student;
import safeluck.drive.evaluation.DB.WokViewModel;
import safeluck.drive.evaluation.R;
import safeluck.drive.evaluation.adapter.ScoreAdapter;
import safeluck.drive.evaluation.bean.ScoreBean;
 
/**单机训练UI
 * MyApplication2
 * Created by lzw on 2019/3/15. 14:32:50
 * 邮箱:632393724@qq.com
 * All Rights Saved! Chongqing AnYun Tech co. LTD
 */
public class TrainFragment extends SupportFragment implements View.OnClickListener {
 
    private static final String TAG = TrainFragment.class.getSimpleName();
    private ListView mListView ;
    private ScoreAdapter mScoreAdapter;
 
    private List<ScoreBean> mArrayList = new ArrayList<>();
 
 
    public static SupportFragment newInstance(){
        return new TrainFragment();
    }
 
    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.layout_train_fragment,container,false);
        initView(view);
 
        WokViewModel wokViewModel = ViewModelProviders.of(this).get(WokViewModel.class);
        wokViewModel.getStudents().observe(this, new Observer<List<Student>>() {
            @Override
            public void onChanged(List<Student> students) {
                for (Student student:
                     students) {
                    Log.i(TAG, "onChanged: "+student.toString());
                }
            }
        });
 
        return view;
    }
    private void initView(View view) {
        mListView = view.findViewById(R.id.lv);
        view.findViewById(R.id.view_map).setOnClickListener(this);
        mScoreAdapter = new ScoreAdapter(_mActivity);
        mListView.setAdapter(mScoreAdapter);
        mListView.addHeaderView(LayoutInflater.from(_mActivity).inflate(R.layout.layout_score_item,null));
        mArrayList.add(new ScoreBean(12,"直角转弯","后轮胎压线"));
        mArrayList.add(new ScoreBean(100,"倒车入库","未系安全带"));
        mArrayList.add(new ScoreBean(10,"坡道起步","一次熄火"));
        mScoreAdapter.addDatas(mArrayList);
 
    }
 
    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.view_map:
                TcpFragment passwordFragment = findFragment(TcpFragment.class);
                if (passwordFragment == null) {
                    passwordFragment = (TcpFragment) TcpFragment.newInstance();
                    start(passwordFragment);
                } else {
                    start(passwordFragment);
                }
                break;
        }
    }
}