Android-多纱厂 [英] Android- Multiple Spinners
问题描述
我有这个code:
package lijap.app.starcraft2counters;
import java.io.File;
import android.app.Activity;
import android.os.Bundle;
import android.os.Environment;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.ArrayAdapter;
import android.widget.Spinner;
import android.widget.Toast;
public class Settings extends Activity implements OnItemSelectedListener {
Spinner answertime;
Spinner gametime;
Spinner missesallowed;
String[] answerseconds = { "Unlimited", "1 second", "2 seconds", "3 seconds",
"4 seconds", " 5 seconds" };
String[] gameminutes = { "Unlimited", "1 minute", "2 minutes", "3 minutes",
"4 minutes", " 5 minutes" };
String[] numberofmisses = { "Unlimited", "5", "10", "15",
"20", "25" };
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.settings);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(Settings.this,
android.R.layout.simple_spinner_item, gameminutes);
answertime = (Spinner) findViewById(R.id.s_answertime);
answertime.setAdapter(adapter);
answertime.setOnItemSelectedListener(this);
}
@Override
public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2,
long arg3) {
// TODO Auto-generated method stub
}
@Override
public void onNothingSelected(AdapterView<?> arg0) {
// TODO Auto-generated method stub
}
}
我越来越糊涂试图把超过1微调。难道我共享阵列适配器,或做我创建一个新的每一个?怎么样onItemSelected?正如你可以从我的琴弦在上面看到的,我要三纱厂。我将如何做到这一点?
I am getting confused trying to put in more than 1 spinner. Do I share the array adapter, or do I create a new one for each? What about the onItemSelected? As you can see from my strings at the top, I want three spinners. How would I do this?
我是新来的机器人,你可以告诉。所有帮助AP preciated- Lijap
I am new to android, as you can tell. All help is appreciated- Lijap
推荐答案
您可以分享不同的微调
S之间的适配器,如果他们适应了相同的信息。显然,所有的适配器需要适应不同的一组的S 字符串,所以你需要创建一个
ArrayAdapter
为每微调
。
You could share the adapter between different Spinner
s if they adapted the same information. Clearly each of your adapters need to adapt a different set of String
s, so you need to create an ArrayAdapter
for each Spinner
.
一个 OnItemSelectedListener
将工作3 纱厂
(只要你设置)。您可以拨打的getId()
在适配器视图&LT;&GT;
作为参数传递知道哪个微调
引发的事件。
A single OnItemSelectedListener
will work for the 3 Spinners
(as long as you set them). You can call getId()
on the AdapterView<?>
passed as an argument to know which Spinner
raised the event.
public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2,
long arg3) {
switch(arg0.getId()){
case R.id.s_answertime:
break;
case ...
}
}
这篇关于Android-多纱厂的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!