Skip to content

Commit b3a411f

Browse files
committed
study:
- SwipeRefreshLayout 연습 2 - Refresh and Shuffled sample string
1 parent 3798dda commit b3a411f

3 files changed

Lines changed: 35 additions & 22 deletions

File tree

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,32 @@
11
package com.seok.gfd.views
22

33
import android.os.Bundle
4-
import android.os.Handler
4+
import android.widget.ArrayAdapter
55
import androidx.appcompat.app.AppCompatActivity
66
import com.seok.gfd.R
77
import kotlinx.android.synthetic.main.activity_guest_main.*
88
import java.util.*
99

1010
class GuestMain : AppCompatActivity() {
11+
private val arrayList =ArrayList<String>(listOf("First Element", "Second Element", "Third Element", "Fourth Element", "Fifth Element"))
1112

1213
override fun onCreate(savedInstanceState: Bundle?) {
1314
super.onCreate(savedInstanceState)
1415
setContentView(R.layout.activity_guest_main)
1516

17+
val adapter = ArrayAdapter(this, R.layout.simple_list_item_1, arrayList)
18+
listView.adapter = adapter
19+
1620
simpleSwipeRefreshLayout.setOnRefreshListener {
17-
Handler().postDelayed({
18-
simpleSwipeRefreshLayout.isRefreshing = false
19-
val r = Random()
20-
val i1 : Int = r.nextInt(100)
21-
guestTextView.text = i1.toString()
22-
}, 3000)
21+
simpleSwipeRefreshLayout.isRefreshing = false
22+
shuffleItems()
2323
}
2424
}
2525

26+
private fun shuffleItems(){
27+
arrayList.shuffle(Random(System.currentTimeMillis()))
28+
val adapter = ArrayAdapter(this, R.layout.simple_list_item_1, arrayList)
29+
listView.adapter = adapter
30+
}
31+
2632
}
Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
3-
xmlns:app="http://schemas.android.com/apk/res-auto"
43
xmlns:tools="http://schemas.android.com/tools"
54
android:layout_width="match_parent"
65
android:layout_height="match_parent"
@@ -17,20 +16,11 @@
1716
android:orientation="horizontal"
1817
android:padding="20dp">
1918

20-
<TextView
21-
android:layout_width="wrap_content"
22-
android:layout_height="wrap_content"
23-
android:text="Random Number : "
24-
android:textColor="#000"
25-
android:textSize="20sp" />
26-
27-
<TextView
28-
android:id="@+id/guestTextView"
29-
android:layout_width="wrap_content"
30-
android:layout_height="wrap_content"
31-
android:textColor="#000"
32-
android:textSize="20sp" />
33-
19+
<ListView
20+
android:id="@+id/listView"
21+
android:layout_width="match_parent"
22+
android:layout_height="match_parent" />
3423
</LinearLayout>
24+
3525
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
3626
</androidx.constraintlayout.widget.ConstraintLayout>
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
3+
<TextView
4+
5+
xmlns:android="http://schemas.android.com/apk/res/android"
6+
7+
android:id="@+id/TextView1"
8+
9+
android:layout_width="match_parent"
10+
11+
android:layout_height="wrap_content"
12+
13+
android:background="#cae682"
14+
15+
android:textColor="#aec7e1"
16+
17+
android:textSize="30dp" />

0 commit comments

Comments
 (0)