我对片段中的 onClicklistener 有一些问题。如果我点击按钮,什么都不会发生。我既没有收到来自 Logcat 中的 onClicklistener 的消息,也没有在屏幕上出现 Toast,但我在代码中找不到错误。有任何想法吗?
我会很感激任何帮助!非常感谢!对不起我的英语不好
import android.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.EditText;
import android.widget.Button;
import android.widget.Toast;
import android.util.Log;
public class InputFragment extends Fragment
{
EditText input_text;
String text;
Button translate_button;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
View InputFragmentView = inflater.inflate(R.layout.input_fgmt, container, false);
input_text = (EditText) InputFragmentView.findViewById(R.id.input_field);
translate_button = (Button) InputFragmentView.findViewById(R.id.translate);
translate_button.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View view)
{
Log.d("Test", "onClickListener ist gestartet");
Toast.makeText(getActivity().getApplicationContext(), "Test", Toast.LENGTH_LONG).show();
saveInString();
}
});
return inflater.inflate(R.layout.input_fgmt, container, false);
}
public void saveInString()
{
if(text.equals(null))
{
Toast.makeText(getActivity().getApplicationContext(), "Das Feld ist leer!", Toast.LENGTH_SHORT).show();
}
else
{
Toast.makeText(getActivity().getApplicationContext(), "Speichern...", Toast.LENGTH_LONG).show();
text = input_text.getText().toString();
Toast.makeText(getActivity().getApplicationContext(), "Fertig", Toast.LENGTH_SHORT).show();
}
}
}