【发布时间】:2014-01-22 03:42:30
【问题描述】:
我正在构建一个拥有 20 多个微调器的应用。我正在尝试一键重置所有微调器。那可能吗?您能否指导我如何实现这一目标。以下是我的代码。
如果可能的话,我希望从菜单中选择重置(右上角的 3 个点)有人可以帮助我。提前谢谢你:)
package com.example.hfacs_test09;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.ArrayAdapter;
import android.widget.Spinner;
import android.widget.TextView;
public class Unsafe extends Fragment implements OnItemSelectedListener {
private Spinner uhs1a,uhs1b,uhs1c;
private TextView unsaferesult;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.unsafe, container, false);
unsaferesult = (TextView) rootView.findViewById(R.id.unsaferesult);
uhs1a = (Spinner) rootView.findViewById(R.id.uhs1a);
uhs1b = (Spinner) rootView.findViewById(R.id.uhs1b);
uhs1c = (Spinner) rootView.findViewById(R.id.uhs1c);
uhs1a.setOnItemSelectedListener(this);
uhs1b.setOnItemSelectedListener(this);
uhs1c.setOnItemSelectedListener(this);
return rootView;
}
public void onItemSelected(AdapterView<?> parent, View view, int position,
long id){
//uhs1a.setSelection(position);
int r1 = Integer.valueOf((String) uhs1a.getSelectedItem());
int r2 = Integer.valueOf((String) uhs1b.getSelectedItem());
int r3 = Integer.valueOf((String) uhs1c.getSelectedItem());
int total = r1 + r2 + r3;
//int myresult = (Integer) uhs1a.getSelectedItem() ;
unsaferesult.setText("Total Score is " + total);
}
public void onNothingSelected(AdapterView<?> parent) {
}
}
【问题讨论】:
标签: android spinner default-value