안드로이드 앱에서 다이얼로그를 띄우는 방법입니다.
메인액티비티에서 다이얼로그를 표시하는 방법은 아래와 같습니다.
다이얼로그 레이아웃을 만듭니다.
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_margin="15dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/textview_score_name4"
style="@style/sub_subtitle_text"
/>
</LinearLayout>
<LinearLayout
android:id="@+id/layout_score_graph_linechart"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.github.mikephil.charting.charts.LineChart
android:id="@+id/chart_score_graph"
android:layout_width="match_parent"
android:layout_height="match_parent"
style="@style/sub_chart"/>
</LinearLayout>
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
위는 차트를 표시하는 다이얼로그 레이아웃입니다. 간단히 텍스트만 표시하는 걸로 테스트 해보셔도 됩니다.
다이얼로그 클래스를 생성합니다.
public GraphDialog(Context context, List<DataControl> datalist) {
super(context);
setContentView(R.layout.graph_dialog);
m_nScore_For_Graph = new ArrayList<DataControl>(datalist);
layout_linechart = findViewById(R.id.layout_score_graph_linechart);
DrawScoreGraph();
}
위 다이얼로그 클래스는 생성과 동시에 데이터를 받기 위해 리스트를 전달받도록 했습니다.
메인액티비티에서 다이얼로그를 호출합니다.
// 가점변화 그래프 다이얼로그 //////////////////////////
btnDialog.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
graphDialog = new GraphDialog(MainActivity.this, m_nScore_For_Graph);
graphDialog.show();
}
});
m_nScore_For_Graph 변수를 다이얼로그 클래스에 전달하면서 다이얼로그 클래스를 생성합니다.
다이얼로그를 띄우는 간단한 방법입니다!
'안드로이드' 카테고리의 다른 글
안드로이드앱의 데이터 보안 양식 잘못됨 해결 - SPLIT_BUNDLE 28 (0) | 2023.08.25 |
---|---|
구글플레이스토어 콘솔 테스트용 앱번들 삭제, 그리고 버전관리의 중요성 (0) | 2023.08.22 |
안드로이드스튜디오 앱 패키지명 변경 방법. example 명칭 제거 (0) | 2023.07.07 |
안드로이드 다이얼로그 크기 설정방법 (0) | 2023.07.05 |
노트북 개발환경 설정하기 - 안드로이드스튜디오설치, 깃허브 연결 (0) | 2023.05.24 |