Skip to content

Commit

Permalink
Fixed setSpinnerHint doesn't show label issue
Browse files Browse the repository at this point in the history
  • Loading branch information
sadra committed Apr 6, 2019
1 parent 0549cfd commit 11d4166
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 28 deletions.
4 changes: 2 additions & 2 deletions AwesomeSpinner/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ android {
defaultConfig {
minSdkVersion 14
targetSdkVersion 26
versionCode 15
versionName "1.5.0"
versionCode 16
versionName "1.5.1"

testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ allprojects {

**Step 2.** Add the dependency:
```groovy
implementation 'com.github.sadra:AwesomeSpinner:1.5.0'
implementation 'com.github.sadra:AwesomeSpinner:1.5.1'
```

## How To Use
Expand Down
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ android {
applicationId "com.isapanah.awsomespinnerexample"
minSdkVersion 14
targetSdkVersion 26
versionCode 15
versionName "1.5.0"
versionCode 16
versionName "1.5.1"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@
import java.util.ArrayList;
import java.util.List;

public class MainActivity extends AppCompatActivity {

public class MainActivity extends AppCompatActivity
{
AwesomeSpinner spinnerRTL, spinnerLTR;


@Override
protected void onCreate(Bundle savedInstanceState) {
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);
Expand All @@ -42,9 +42,11 @@ protected void onCreate(Bundle savedInstanceState) {
//Initialize the Adapter and spinnerRTL listener
ArrayAdapter<CharSequence> provincesAdapter = ArrayAdapter.createFromResource(this, R.array.iran_provinces, android.R.layout.simple_spinner_item);
spinnerRTL.setAdapter(provincesAdapter, 0);
spinnerRTL.setOnSpinnerItemClickListener(new AwesomeSpinner.onSpinnerItemClickListener<String>() {
spinnerRTL.setOnSpinnerItemClickListener(new AwesomeSpinner.onSpinnerItemClickListener<String>()
{
@Override
public void onItemSelected(int position, String itemAtPosition) {
public void onItemSelected(int position, String itemAtPosition)
{
Toast.makeText(getApplicationContext(), "Position: "+position+" | Item: "+itemAtPosition+" | isSelected:"+spinnerLTR.isSelected(), Toast.LENGTH_LONG).show();
}
});
Expand All @@ -61,16 +63,21 @@ public void onItemSelected(int position, String itemAtPosition) {

ArrayAdapter<String> categoriesAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, categories);
spinnerLTR.setAdapter(categoriesAdapter);
spinnerLTR.setOnSpinnerItemClickListener(new AwesomeSpinner.onSpinnerItemClickListener<String>() {
spinnerLTR.setOnSpinnerItemClickListener(new AwesomeSpinner.onSpinnerItemClickListener<String>()
{
@Override
public void onItemSelected(int position, String itemAtPosition) {
public void onItemSelected(int position, String itemAtPosition)
{
Toast.makeText(getApplicationContext(), "Position: "+position+" | Item: "+itemAtPosition+" | isSelected:"+spinnerLTR.isSelected(), Toast.LENGTH_LONG).show();
}
});

new Handler().postDelayed(new Runnable() {
public void run() {
runOnUiThread(new Runnable() {
new Handler().postDelayed(new Runnable()
{
public void run()
{
runOnUiThread(new Runnable()
{
@Override
public void run() {
spinnerLTR.setSelection(2);
Expand All @@ -81,10 +88,11 @@ public void run() {


FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
fab.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View view) {

public void onClick(View view)
{
//Or you can check for spinnerLTR as the same way
if(spinnerRTL.isSelected()){
Snackbar.make(view, "Yes, spinnerRTL is selected the item: "+spinnerRTL.getSelectedItem()+".", Snackbar.LENGTH_LONG)
Expand All @@ -93,15 +101,13 @@ public void onClick(View view) {
Snackbar.make(view, "No, spinnerRTL doesn't select anything yet!", Snackbar.LENGTH_LONG)
.setAction("OK", null).show();
}

spinnerRTL.setSpinnerHint("تست هینت");

}
});


final Button disable_spinners = (Button) findViewById(R.id.disable_spinners);
disable_spinners.setOnClickListener(new View.OnClickListener() {
disable_spinners.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View v) {
if(spinnerLTR.isSpinnerEnable()){
Expand All @@ -116,21 +122,20 @@ public void onClick(View v) {
}
});

findViewById(R.id.deselect_rtl).setOnClickListener(new View.OnClickListener() {
findViewById(R.id.deselect_rtl).setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View v) {
spinnerRTL.clearSelection();
}
});

findViewById(R.id.deselect_ltr).setOnClickListener(new View.OnClickListener() {
findViewById(R.id.deselect_ltr).setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View v) {
spinnerLTR.clearSelection();
}
});


}

}

0 comments on commit 11d4166

Please sign in to comment.