我用onclick按钮打开spiiner,但我的微调器不是
触发setOnItemSelectedListener这部分代码不起作用public void onItemSelected(AdapterView arg0,View arg1,
int pos,
长ID){
语言= AppConstants.Language_arr [pos];
}
public void onNothingSelected(AdapterView<?> arg0) {
// TODO Auto-generated method stub
} spinner opens but onitemselected is not working
import com.privy.constants.AppConstants;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.Spinner;
import android.widget.ToggleButton;
public class Settings extends Activity implements OnClickListener {
private Spinner sp_languge, sp_login;
private ToggleButton toggle_news_letter;
private String language;
private Button language_change;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.settings);
sp_languge = new Spinner(this);
ArrayAdapter<String> adapter_language = new ArrayAdapter<String>(
Settings.this, R.layout.spinner_item, AppConstants.Language_arr);
sp_languge.setAdapter(adapter_language);
language_change = (Button) findViewById(R.id.language_change);
language_change.setOnClickListener(this);
sp_languge.setOnItemSelectedListener(new OnItemSelectedListener() {
public void onItemSelected(AdapterView<?> arg0, View arg1, int pos,
long id) {
language = AppConstants.Language_arr[pos];
}
public void onNothingSelected(AdapterView<?> arg0) {
// TODO Auto-generated method stub
}
});
}
public void onClick(View v) {
if (v == language_change) {
sp_languge.performClick();
}
}
}
最佳答案
在XMl中添加微调器,宽度/高度为零...
和使用
sp_languge = (Spinner)findViewById(R.id.<my_spinerid>);
android spinner performClick onItemSelected
关于android - onItemSelected/setOnItemSelectedListener不触发,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/10991824/