当此过程正常工作时,我想制作一个按钮以依次保存/打印/显示 2 个微调器中的名称。
执行用户名时将按下此按钮。例如:
当 item == Linda 时,Linda 按下了按钮。直接按钮将在 spinner1 上显示/打印 Linda 的名字。
其他用户也会发生同样的事情。并且名称将直接保存在后续微调器(Spinner2)中。
这是我的代码...
主程序
该主程序系统用于循环名称。
public boolean onOptionsItemSelected(MenuItem item) {
Log.i(TAG, "Menu Item selected " + item);
if (item == Linda) {
variabel.setViewMode(ClassOne.Object1);
new Thread(new Runnable(){
public void run() {
try {
Thread.sleep(5000);
onOptionsItemSelected(David);}
catch (Exception ex){}}
}).start();
} else if (item == David) {
variabel.setViewMode(ClassOne.Object2);
new Thread(new Runnable(){
public void run() {
try {
Thread.sleep(5000);
onOptionsItemSelected(Samuel);}
catch (Exception ex){}}
}).start();
} else if (item == Samuel) {
variabel.setViewMode(ClassOne.Object3);
new Thread(new Runnable(){
public void run() {
try {
Thread.sleep(5000);
onOptionsItemSelected(Linda);}
catch (Exception ex){}}
}).start();
}
微调程序
这是我的代码...
private Spinner spinner1, spinner2;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
addListenerOnButton();
addListenerOnSpinnerItemSelection();
}
public void addListenerOnSpinnerItemSelection() {
spinner1 = (Spinner) findViewById(R.id.spinner1);
spinner1.setOnItemSelectedListener(new CustomOnItemSelectedListener());
spinner2 = (Spinner) findViewById(R.id.spinner2);
spinner2.setOnItemSelectedListener(new CustomOnItemSelectedListener());
// get the selected dropdown list value
public void addListenerOnButton() {
spinner1 = (Spinner) findViewById(R.id.spinner1);
spinner2 = (Spinner) findViewById(R.id.spinner2);
public void onClick(View v) {
/* get names when button stop on looping process and print the names in spinners*/
String name1 = String.valueOf(spinner1.getSelectedItem());
String name2 = String.valueOf(spinner2.getSelectedItem());
String print_name = getName(name1);
String print_name = getName(name2);
public String getName(String name) {
String value = "0";
if (name.equalsIgnoreCase("Linda")) {
value = "0";
} else if (name.equalsIgnoreCase("David")) {
value = "1";
} else if (name.equalsIgnoreCase("Samuel")) {
value = "2"; }
字符串.XML
<string-array name="names">
<item>Linda</item>
<item>David</item>
<item>Samuel</item>
我的问题:
如何创建一个按钮,我应该把可以直接打印/显示所选名称的按钮放在哪里?