Skip to content

Commit 173a54a

Browse files
author
Shaon
committed
Java example added
1 parent 6f28d06 commit 173a54a

5 files changed

Lines changed: 86 additions & 7 deletions

File tree

app/src/main/AndroidManifest.xml

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,4 @@
11
<?xml version="1.0" encoding="utf-8"?>
2-
<!--
3-
~ Copyright (c) 2020.
4-
~ Ashiqul Islam
5-
-->
6-
72
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
83
package="com.lastblade.spinnerdialogtest">
94

@@ -21,6 +16,7 @@
2116
<category android:name="android.intent.category.LAUNCHER" />
2217
</intent-filter>
2318
</activity>
19+
<activity android:name=".MainActivity2" />
2420
</application>
2521

2622
</manifest>

app/src/main/java/com/lastblade/spinnerdialogtest/MainActivity.kt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,6 @@ class MainActivity : AppCompatActivity() {
2626
title("Title")
2727
listValues(data) { text, position ->
2828
this@MainActivity.tv.text = "Selected item: $text"
29-
30-
dismiss()
3129
}
3230

3331
negativeButton()
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/*
2+
* Copyright (c) 2020.
3+
* Ashiqul Islam
4+
*/
5+
6+
package com.lastblade.spinnerdialogtest;
7+
8+
import androidx.appcompat.app.AppCompatActivity;
9+
10+
import android.app.Dialog;
11+
import android.os.Bundle;
12+
import android.util.Log;
13+
import android.view.View;
14+
import android.widget.TextView;
15+
16+
import com.lastblade.rvdialog.RvDialog;
17+
18+
import java.util.ArrayList;
19+
20+
public class MainActivity2 extends AppCompatActivity {
21+
22+
@Override
23+
protected void onCreate(Bundle savedInstanceState) {
24+
super.onCreate(savedInstanceState);
25+
setContentView(R.layout.activity_main2);
26+
27+
ArrayList items = new ArrayList<String>();
28+
items.add("Mango");
29+
items.add("Apple");
30+
31+
32+
TextView tv = findViewById(R.id.tv);
33+
34+
findViewById(R.id.btnShowDialog).setOnClickListener(v -> {
35+
new RvDialog(this)
36+
.title("Title")
37+
.negativeButton()
38+
.listValues(items, (item, index) -> {
39+
tv.setText(item);
40+
return null;
41+
})
42+
.show();
43+
});
44+
45+
46+
}
47+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!--
3+
~ Copyright (c) 2020.
4+
~ Ashiqul Islam
5+
-->
6+
7+
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
8+
xmlns:app="http://schemas.android.com/apk/res-auto"
9+
xmlns:tools="http://schemas.android.com/tools"
10+
android:layout_width="match_parent"
11+
android:layout_height="match_parent"
12+
android:gravity="center"
13+
android:orientation="vertical"
14+
tools:context=".MainActivity">
15+
16+
<TextView
17+
android:gravity="center"
18+
android:id="@+id/tv"
19+
android:layout_width="match_parent"
20+
android:layout_height="wrap_content"
21+
android:text="Selected Value:" />
22+
23+
<Button
24+
android:layout_marginTop="16dp"
25+
android:id="@+id/btnShowDialog"
26+
android:layout_width="wrap_content"
27+
android:layout_height="wrap_content"
28+
android:text="Show dialog"
29+
app:layout_constraintBottom_toBottomOf="parent"
30+
app:layout_constraintLeft_toLeftOf="parent"
31+
app:layout_constraintRight_toRightOf="parent"
32+
app:layout_constraintTop_toTopOf="parent" />
33+
34+
35+
</LinearLayout>

rvdialog/src/main/java/com/lastblade/rvdialog/RvDialog.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ class RvDialog(context: Context) : Dialog(context, R.style.customRVDialog) {
3535
v.tv.text = text
3636
}
3737

38+
@JvmOverloads
3839
fun listValues(
3940
data: ArrayList<String>,
4041
handler: (text: String, position: Int) -> Unit
@@ -43,6 +44,7 @@ class RvDialog(context: Context) : Dialog(context, R.style.customRVDialog) {
4344
v.rv.adapter = RvSpinnerAdapter(data, handler)
4445
}
4546

47+
@JvmOverloads
4648
fun negativeButton(text: String = "Cancel"): RvDialog = apply {
4749
cancel.text = text
4850
cancel.setOnClickListener { dismiss() }
@@ -78,6 +80,7 @@ class RvDialog(context: Context) : Dialog(context, R.style.customRVDialog) {
7880

7981
tv.setOnClickListener {
8082
handler(value, adapterPosition)
83+
dismiss()
8184
}
8285
}
8386
}

0 commit comments

Comments
 (0)