Skip to content

Repository files navigation

SearchViewDialog - Easy Drop Down


Simple way to select Item Single or Multi


Content List


Download

Add maven jitpack.io and dependencies in build.gradle (Project) :

// build.gradle projectallprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
// build.gradle app/moduledependencies {
...
implementation 'com.google.android.material:material:1.2.1'
implementation 'com.github.gzeinnumer:SearchViewDialog:version'
implementation 'com.github.gzeinnumer:SimpleMaterialStyle:last-vesion'//check on https://github.com/gzeinnumer/SimpleMaterialStyle
}

Feature List


Tech stack and 3rd library

  • Material.io (docs)
  • Multi and Single Selection in Recyclerview (docs) (example)
  • DialogFragment (docs)

Usage

First Step. Use MaterialComponents in your style :

<stylename="AppTheme"parent="Theme.MaterialComponents.Light.NoActionBar">
<!-- Customize your theme here. -->
</style>
<stylename="CustomDialogStyle"parent="Theme.MaterialComponents.Light.Dialog">
<itemname="colorPrimary">@color/colorPrimary</item>
<itemname="colorPrimaryDark">@color/colorPrimaryDark</item>
<itemname="colorAccent">@color/colorAccent</item>
<itemname="android:windowMinWidthMajor">80%</item>
<itemname="android:windowMinWidthMinor">80%</item>
<itemname="android:windowEnterAnimation">@anim/anim_in</item>
<itemname="android:windowExitAnimation">@anim/anim_out</item>
</style>

Add This Line to res/color.xml. Important

<?xml version="1.0" encoding="utf-8"?>
<resources>
<colorname="colorPrimary">#6200EE</color>
<colorname="colorPrimaryDark">#3700B3</color>
<colorname="colorAccent">#03DAC5</color>
</resources>

If you want to change default font, add custom_font.ttf to your res directory res->font. Than add this style to your style.xml/themes.xml

<!-- Base application theme. --><!-- Change Base Font -->
<stylename="Theme.MyLibsTesting"parent="Theme.MaterialComponents.DayNight.DarkActionBar">
<itemname="android:fontFamily">@font/test_font</item>
</style>
<!-- Change TextView Font -->
<stylename="BaseTextView">
<itemname="android:fontFamily">@font/test_font</item>
</style>
<stylename="BaseTextView.Bold"parent="BaseTextView">
<itemname="android:fontFamily">@font/test_font</item>
</style>
<stylename="BaseTextView.Italic"parent="BaseTextView">
<itemname="android:fontFamily">@font/test_font</item>
</style>
<stylename="BaseTextView.Bold.Italic"parent="BaseTextView">
<itemname="android:fontFamily">@font/test_font</item>
</style>
<!-- Change Button Font -->
<stylename="MyButtonText"parent="Widget.MaterialComponents.Button.TextButton">
<itemname="android:fontFamily">@font/test_font</item>
</style>
<stylename="MyButtonOutlined"parent="Widget.MaterialComponents.Button.OutlinedButton">
<itemname="android:fontFamily">@font/test_font</item>
</style>
<stylename="MyButtonContained">
<itemname="android:fontFamily">@font/test_font</item>
</style>
<stylename="MyButtonIcon"parent="Widget.MaterialComponents.Button.Icon">
<itemname="android:fontFamily">@font/test_font</item>
</style>

SearchViewDialog

Dialog with 1 Title, 1 Content, 1 EditText, 1 RecyclerView, 1 Negative Button, 1 Positive Button. You can choise Single Item Select or Multi Item Select. The difference is only in callback function.

  • Content Item there is 3 types data that you can sent to this dialog.

Type 1

String[] arrayString = {"M", "Fadli", "Zein"};
newSearchViewDialog<String>(getSupportFragmentManager())
.setItems(arrayString);

Type 2

ArrayList<String> listString = newArrayList<>();
listString.add("Lorem ipsum dolor");
newSearchViewDialog<String>(getSupportFragmentManager())
.setItems(listString);

Type 3 for this type you should override function toString() in your model pojo

publicclassExampleModel {
privateintid;
privateStringname;
privateStringaddress;
//constructor//getter//setter@OverridepublicStringtoString() {
return"ExampleModel{" +
"id=" + id +
", name='" + name + '\'' +
", address='" + address + '\'' +
'}';
}
}

And dont forget to declare your model pojo after SearchViewDialog<ModelPojo>

ArrayList<ExampleModel> listObject = newArrayList<>();
listObject.add(newExampleModel(1, "Zein", "Balbar"));
newSearchViewDialog<ExampleModel>(getSupportFragmentManager())
.setItems(listObject);

use your model pojo to callBack function. Example new SearchViewDialog.OnOkPressedSingle<ExampleModel>(){} or new SearchViewDialog.OnOkPressedMulti<ExampleModel>(){}

//For SinglenewSearchViewDialog<ExampleModel>(getSupportFragmentManager())
.setItems(listObject)
.onOkPressedCallBackSingle(...);
//For MultinewSearchViewDialog<ExampleModel>(getSupportFragmentManager())
.setItems(listObject)
.onOkPressedCallBackMulti(...);

  • Single Item Select. Use onOkPressedCallBackSingle to enable Single Select Item. Code :
ArrayList<String> list = newArrayList<>();
list.add("Lorem ipsum dolor");
list.add("sit amet, consectetur");
list.add("adipiscing elit sed do");
newSearchViewDialog<String>(getSupportFragmentManager())
.setItems(list)
.setTitle("ini title")
.setContent("ini content")
.onOkPressedCallBackSingle(newSearchViewDialog.OnOkPressedSingle<String>() {
@OverridepublicvoidonOkSingle(Stringdata) {
Stringtemp = "Single Select : \n"+data.toString();
tv.setText(temp);
}
})
.onCancelPressedCallBack(newSearchViewDialog.OnCancelPressed() {
@OverridepublicvoidonCancelPressed() {
Toast.makeText(MainActivity.this, "Cancel", Toast.LENGTH_SHORT).show();
}
})
.show();

  • Multi Item Select. Use onOkPressedCallBackMulti to enable Multi Select Item. Code :
ArrayList<String> list = newArrayList<>();
list.add("Lorem ipsum dolor");
list.add("sit amet, consectetur");
list.add("adipiscing elit sed do");
newSearchViewDialog<String>(getSupportFragmentManager())
.setItems(list)
.setTitle("ini title")
.setContent("ini content")
.onOkPressedCallBackMulti(newSearchViewDialog.OnOkPressedMulti<String>() {
@OverridepublicvoidonOkMulti(List<String> data) {
Stringtemp = "Multi Select :\n";
temp = temp + "Total Data => "+data.size()+"\n\n";
for (Stringd: data){
temp = temp + "Value => "+ d +"\n";
}
tv.setText(temp);
}
})
.onCancelPressedCallBack(newSearchViewDialog.OnCancelPressed() {
@OverridepublicvoidonCancelPressed() {
Toast.makeText(MainActivity.this, "Cancel", Toast.LENGTH_SHORT).show();
}
})
.show();

or you can write code like this :

SearchViewDialogdialog = newSearchViewDialog<String>(getSupportFragmentManager())
.setItems(list)
.setTitle("ini title")
.setContent("ini content");
dialog.onOkPressedCallBackMulti(newSearchViewDialog.OnOkPressedMulti<String>(){
@OverridepublicvoidonOkMulti(List<String> data) {
}
}).
dialog.onCancelPressedCallBack(newSearchViewDialog.OnCancelPressed<String>() {
@OverridepublicvoidonCancelPressed() {
Toast.makeText(MainActivity.this, "Cancel", Toast.LENGTH_SHORT).show();
}
});
dialog.show();

Preview :

Single Select Item Preview, you only can select 1 ItemClick OK and call function onOkPressedCallBackSingleFiture Filter will enable on Single Select or Multi Select
Multi Select Item Preview, you can select more than 1 ItemClick OK and call function onOkPressedCallBackMulti

SearchViewDialog -> Customize

You can Customize your dialog UI. ReadMore.


Example Code/App

FullCode MainActivity

Sample Code And App


Version

  • 2.0.3
    • First Release
  • 2.0.4
    • Add animation and set custom animation show
  • 2.0.5
    • Bug Fixing
  • 2.0.6
    • Color
  • 2.0.8
    • Bug Fixing
  • 2.0.9
    • Bug Fixing
  • 2.1.0
    • Bug Fixing Color
  • 2.1.1
    • Bug Fixing Color
  • 3.0.0
    • Support SDK 16
  • 3.0.1
    • Bug Color
  • 3.0.3
    • Bug Fixing
  • 3.0.4
    • Bug Fixing
  • 3.0.5
    • Bug Fixing
  • 3.0.6
    • Bug Fixing
  • 3.0.7
    • Bug Fixing
  • 3.0.7
    • Fixing Space
  • 3.1.0
    • New Style
  • 3.1.2
    • Bug Fixing
  • 3.1.3
  • 3.1.4
    • Enable Disable Filter
  • 3.1.5
    • Disable order on search
  • 3.1.6
    • Max length On Teks set to 30 and olny single line

Contribution

You can sent your constibution to branchopen-pull.


Copyright 2020 M. Fadli Zein

About

Dialog Search Single or Multi item Selection

Resources

Stars

6 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages