Created
August 13, 2018 07:41
-
-
Save sharifulislam52/de91bfa543260323809b97009febec23 to your computer and use it in GitHub Desktop.
Full Example of MultiSelectedSpinner
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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" | |
android:padding="10dp" | |
tools:context="posoft.shariful.multispinner.MainActivity"> | |
<shariful.MultiSelectedSpinner | |
android:id="@+id/multi_selected_spinner" | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content"/> | |
<TextView | |
android:id="@+id/showResult" | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content" | |
android:textSize="19sp" | |
android:text="Selected items will show here." | |
android:layout_marginTop="50dp"/> | |
</LinearLayout> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package posoft.shariful.multispinner; | |
import android.support.v7.app.AppCompatActivity; | |
import android.os.Bundle; | |
import android.view.View; | |
import android.widget.TextView; | |
import java.util.ArrayList; | |
import shariful.MultiSelectedSpinner; | |
public class MainActivity extends AppCompatActivity { | |
TextView showResult; | |
MultiSelectedSpinner mss; | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_main); | |
mss = (MultiSelectedSpinner) findViewById(R.id.multi_selected_spinner); | |
ArrayList<String> list = new ArrayList<String>(); | |
list.add("one"); | |
list.add("two"); | |
list.add("three"); | |
list.add("four"); | |
list.add("five"); | |
list.add("six"); | |
list.add("seven"); | |
list.add("eight"); | |
list.add("nine"); | |
list.add("ten"); | |
mss.setItems(list, "Select Items", "ok"); | |
showResult = (TextView) findViewById(R.id.showResult); | |
mss.getSelectedItems(new MultiSelectedSpinner.getItemsList(){ | |
@Override | |
public void itemsList(ArrayList<String> selected_items){ | |
StringBuffer all_items = new StringBuffer(); | |
for (String item : selected_items){ | |
all_items.append(item+", "); | |
} | |
showResult.setText("Auto Complete >>> "+ all_items.toString()); | |
} | |
}); | |
showResult.setOnClickListener(new View.OnClickListener() { | |
@Override | |
public void onClick(View view) { | |
ArrayList<String> result = mss.getSelectedItems(); | |
StringBuffer all_items = new StringBuffer(); | |
for (String item : result){ | |
all_items.append(item+", "); | |
} | |
showResult.setText("Onclick >>> "+all_items.toString()); | |
} | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment