我开始从事 Java/Android 开发。我正在制作一个带有多个选项卡和滑动导航的调查类型应用程序。(基于 SDK/eclipse 示例)。
我有一个片段(选项卡)用一些微调器为视图充气,我需要在另一个片段中创建一个重置按钮,将所有微调器重置到位置 0。
带有微调器的片段。
public class Viagem extends Fragment
{
public Spinner spinLinhaO;
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState)
{
View view2 = inflater.inflate(R.layout.activity_viagem, container, false);
final Spinner spinLinhaO = (Spinner) view2.findViewById(R.id.spinnerO1);
// with the adapter to populate it
}
带有按钮的片段。
public class Inicio extends Fragment
{
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState)
{
View view3 = inflater.inflate(R.layout.activity_menu, container, false);
final Button button = (Button) view3.findViewById(R.id.buttonInq);
button.setOnClickListener(new View.OnClickListener() {
public void onClick(View view3) {
Viagem.spinLinhaO.setSelection(0); //this does not work
}
你能帮我解决这个问题吗?