gpt4 book ai didi

android - onItemSelected/setOnItemSelectedListener 未触发

转载 作者:行者123 更新时间:2023-11-30 04:10:07 27 4
gpt4 key购买 nike

I am opening spiiner with onclick on button but my spinner is not trigger setOnItemSelectedListener this portion of code is not working 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

} 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 上添加 spiiner......................

并使用

sp_languge = (Spinner)findViewById(R.id.<my_spinerid>);

android spinner performClick onItemSelected

关于android - onItemSelected/setOnItemSelectedListener 未触发,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10991824/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com