我开始使用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
}
你能帮帮我解决这个问题吗?