gpt4 book ai didi

java - 旋转器和 Android

转载 作者:行者123 更新时间:2023-12-02 08:19:53 24 4
gpt4 key购买 nike

我想获取微调器的值并将其转换为字符串来使用。

    Spinner s1 = (Spinner)findViewById(R.id.spinner1);
s1.setOnItemSelectedListener((OnItemSelectedListener) this);
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this, R.array.languages, android.R.layout.simple_spinner_item);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
s1.setAdapter(adapter);

我认为这样的事情会起作用......

 private OnClickListener sendClickListener = new OnClickListener(){
public void onClick(View arg0) {
EditText dstName = (EditText) findViewById(R.id.destinationAddress);
EditText dstLanguage = (EditText) findViewById(R.id.spinner1);

String address = dstName.getText().toString();
String language = dstLanguage.getText().toString();

ops.createSocketConnection(language, address);
Notification notification = new Notification();
notification.vibrate = new long[] {100};
}};

可惜事实并非如此......

我看过一些例子,但我不确定它们是否与我的问题直接相关。

提前致谢!

最佳答案

试试这个:

OnItemSelectedListener itemSelectedHandler = new OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View v, int pos, long row) {
String str = parent.getItemAtPosition(pos).toString();
// Do whatever you want with the string
}
@Override
public void onNothingSelected(AdapterView<?> arg0) {
// Do nothing
}
};
//set the spinner's listener for select event

mSpinner.setOnItemSelectedListener(itemSelectedHandler);

关于java - 旋转器和 Android,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5680705/

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