我如何从android中的另一个类打印输出?

时间:2016-04-23 15:06:35

标签: java android class fragment

我正在做这个项目。当用户在微调器中选择位置并单击下一步时,它将显示来自另一个类的结果。但是当我跑步时,它没有做任何事情。事实上,按钮也没有功能。我不知道是什么问题。如果你们能帮助我,那就太好了。谢谢。这是我的源代码。

这是包含微调器的片段

ThisEscape

}

这是我想打电话的课程

public class LetsGoFragment extends Fragment implements View.OnClickListener{

//constructor
public static LetsGoFragment newInstance(){
    LetsGoFragment fragment = new LetsGoFragment();
    return fragment;
}

public LetsGoFragment(){
}

//variable to connect
Spinner spinnerTo;
Spinner spinnerFrom;

Button button;

public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    //connecting the  fragment to layout
    View rootView = inflater.inflate(R.layout.fragment_lets_go, container, false);

    //spinner and button
    spinnerTo = (Spinner) rootView.findViewById(R.id.spinnerTo);
    String textTo = spinnerTo.getSelectedItem().toString();

    spinnerFrom = (Spinner) rootView.findViewById(R.id.spinnerFrom);
    String textFrom = spinnerTo.getSelectedItem().toString();

    button = (Button) rootView.findViewById(R.id.button);

    return rootView;


}


@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);



}

private void setContentView(int activity_main) {
}


@Override
public void onClick(View v) {

    if(spinnerTo.getSelectedItem().equals("Masjid Jamek")&& spinnerFrom.getSelectedItem().equals("Bukit Bintang")){
        MasjidJamekToBukitBintang.class.toString();
    }


}

}

1 个答案:

答案 0 :(得分:0)

您未在onClickListener

上设置button

您需要设置onClickListener,以便在点击""时使button行为。

您需要执行以下操作:

button.setOnClickListener(new View.OnClickListener() {
    public void onClick(View v) {
        // Put here the code you want to run everytime the button is clicked
    }
}