我使用MySQL中的項目製作了微調控件。在MySQL中,我有兩個具有相同值的項目。在微調器中,我有2個重複的東西。當我嘗試選擇第二個時,我得到第一個位置(這是不正確的),當我選擇第一個時,我得到第一個位置(這是正確的)。Android微調項目重複項只給出第一個重複項的位置
代碼:
sp.setVisibility(View.VISIBLE);
//BIND
final ArrayAdapter adapter = new ArrayAdapter(c, android.R.layout.simple_spinner_dropdown_item, optochtenarray){
@Override
public View getDropDownView(int position, View convertView, ViewGroup parent) {
View itemView = super.getDropDownView(position, convertView, parent);
if (position == mSelectedIndex) {
itemView.setBackgroundColor(Color.rgb(56,184,226));
}
else {
itemView.setBackgroundColor(Color.TRANSPARENT);
}
return itemView;
}
};
sp.setAdapter(adapter);
//call ID
sp.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parentView, View view, int position, long id) {
String selectedItem = sp.getSelectedItem().toString();
if (selectedItem != "Kies..."){
//kleur veranderen
mSelectedIndex = sp.getSelectedItemPosition();
Log.e("selectPosition", Integer.toString(mSelectedIndex));
Log.e("ID", idarray.get(position));
//naar de volgende pagina met de 'ID'
Intent myIntent = new Intent(c, gekozenOptocht.class);
myIntent.putExtra("ID", idarray.get(position)); //Optional parameters
c.startActivity(myIntent);
sp.setSelection(adapter.getPosition("Kies..."));
}
}
@Override
public void onNothingSelected(AdapterView<?> parentView) {
// your code here
}
});
爲什麼我收到的第一個位置的時候我儘量選擇第二個?
使用'selectedItem.equals(「Kies ...」)' –