C.E/Java
[Android] 간단한 ListView 구현 예제
숨[Breath]
2021. 4. 1. 17:54
[VIEW]
[XML]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".AlarmSetActivity">
<ListView
android:id="@+id/day_list1"
android:layout_width="wrap_content"
android:layout_height="match_parent"
>
</ListView>
</LinearLayout>
|
cs |
[Activity]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
public class AlarmSetActivity extends AppCompatActivity {
public static final ArrayList<String> DAYLIST = new ArrayList<String>(
Arrays.asList("월요일","화요일","수요일")
);
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_alarm_set);
ListView listView = (ListView)findViewById(R.id.day_list1);
List<String> list = new ArrayList<>();
ArrayAdapter<String> adapter = new ArrayAdapter<>(this, android.R.layout.simple_list_item_1,list);
listView.setAdapter(adapter);
list.addAll(DAYLIST);
}
}
|
cs |
Activity명 : activity_alarm_set.java
XML명 : activity_alarm_set.xml
도움이 되었으면 좋겠습니다. :)