Comments (10)
@pzienowicz sorry, I missed the previous message. I think the listener should be called when selecting the item programmatically. I'm adding this to my TODO list, or feel free to open a PR. :)
from nice-spinner.
To programatically select an option and call its click listener, I added this library as module to my project so that I can edit its file.
selectSiteSpinner.selectedIndex =0
val fakeView = this.context?.let { FrameLayout(it) }
selectSiteSpinner.onSpinnerItemSelectedListener.onItemSelected(
selectSiteSpinner,
selectSiteSpinner.adapter.getView(selectSiteSpinner.selectedIndex, null, fakeView),
selectSiteSpinner.selectedIndex,
selectSiteSpinner.adapter.getItemId(selectSiteSpinner.selectedIndex)
)
from nice-spinner.
Is not a bug , unfurtunatelly is the base android behaviour
from nice-spinner.
Use AdapterView.OnItemSelectedListener instead of SimpleItemSelectedListener
Spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
Log.d("Spinner",list.get(position));
//Do your thing here
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
Log.d("Spinner","Nothing Selected!");
}
});
from nice-spinner.
I have same problem but I already have used AdapterView & set selectedIndex to 0.
Still not working.
Tried Code:
spinnerProperties.attachDataSource(propertyNamesList);
spinnerProperties.setSelectedIndex(0);
spinnerProperties.setSelected(true);
spinnerProperties.setOnItemSelectedListener(onPropertyNameSelected);
AdapterView.OnItemSelectedListener onPropertyNameSelected = new
AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> adapterView, View view, int position, long l) {
Log.d(TAG, "Selected Property: " + position);
}
@Override
public void onNothingSelected(AdapterView<?> adapterView) {
}
};
please help me to solve this issue @arcadefire
from nice-spinner.
Not sure what's the problem here.
from nice-spinner.
The problem is, that when we set selected index programmatically, OnItemSelectedListener is not called.
@arcadefire is it a normal behavior? How can I run listener when changed selected index in code?
from nice-spinner.
@arcadefire could you just let us know if this is normal behavior and we need to handle it by ourselves or just a bug?
from nice-spinner.
termsSpinner.setSelectedIndex(1); // set selection to any non required index
termsSpinner.getListView().performItemClick(termsSpinner.getListView().getChildAt(0), 0, termsSpinner.getListView().getAdapter().getItemId(0)); // 0 is the position we require to be clicked
from nice-spinner.
selectDivision.setText((selectDivisionSpinner.selectedItem as State).name)
We can get selected item from spinner and cast it accordingly, after that we can use its properties
from nice-spinner.
Related Issues (20)
- android 5.1 the arrow not show HOT 2
- arrow not rotating HOT 1
- 无法触发监听
- android:entries didn't work
- 列表长度为0时,会出现adapter.getCount()为null(when the list's size equal 0, the project throw a exception that means adapter.getCount() is null) HOT 3
- 设置layout_height高度时,里面文字只显示一半 HOT 1
- setSelectedIndex crash HOT 3
- Unable to set background
- Hey,guys.There's a very significant problem in this project. HOT 1
- can you add search function && show hint or nothing on start && select can be a panel not just a list! HOT 1
- Spinner drop down arrow not localized
- list列表数据count为1时,pop不弹出(版本1.4.5) HOT 1
- Manifest merger failed with multiple errors, see logs HOT 1
- 在双屏异Presentation中无法使用,无法弹出下拉框
- Nice spinner reference cant be resolved in android studio HOT 5
- dropdown list overlap with anchor view when changing the anchor view background to a transparent image HOT 2
- /storage/emulated/0/qpython/scripts3/buildozer/scripts/client.py
- When I set a custom arrow with arrowDrawable, the arrow does not rotate during operation. What is the problem?
- How to set the drop down height?setDropDownListPaddingBottom not working
- "Why did version 1.4.5 solve the issue of having only one piece of data, but your project homepage still recommends using version 1.4.4?"
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from nice-spinner.