package vn.utt.sotay; import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.widget.Button; import android.widget.LinearLayout; import android.widget.TextView; public final class CourseFlow { private static final String EXTRA_COURSE_ID = "vn.utt.sotay.COURSE_ID"; private static final String[][] COURSES = { {"CTDL01", "Cấu trúc dữ liệu và giải thuật"}, {"KTPM01", "Kiểm thử phần mềm"} }; private static LinearLayout column(Activity screen) { LinearLayout layout = new LinearLayout(screen); layout.setOrientation(LinearLayout.VERTICAL); int padding = Math.round(20 * screen.getResources().getDisplayMetrics().density); layout.setPadding(padding, padding, padding, padding); return layout; } public static class ListActivity extends Activity { @Override protected void onCreate(Bundle state) { super.onCreate(state); LinearLayout layout = column(this); TextView title = new TextView(this); title.setText("Chọn học phần"); title.setTextSize(22); layout.addView(title); for (String[] course : COURSES) { Button button = new Button(this); button.setText(course[1]); button.setOnClickListener(view -> { Intent intent = new Intent(this, DetailActivity.class); intent.putExtra(EXTRA_COURSE_ID, course[0]); startActivity(intent); }); layout.addView(button); } setContentView(layout); } } public static class DetailActivity extends Activity { @Override protected void onCreate(Bundle state) { super.onCreate(state); String code = getIntent().getStringExtra(EXTRA_COURSE_ID); String name = "Không tìm thấy học phần"; for (String[] course : COURSES) { if (course[0].equals(code)) { name = course[1]; break; } } LinearLayout layout = column(this); TextView title = new TextView(this); title.setText(name); title.setTextSize(22); layout.addView(title); Button back = new Button(this); back.setText("Quay lại danh sách"); back.setOnClickListener(view -> finish()); layout.addView(back); setContentView(layout); } } }