我是 Android 的初学者 :( 我正在使用文本输入布局,但我无法捕捉到它们的任何值!这是我的代码。现在我想打印值“usuario”只是为了检查它是否有任何值. 我正在使用 Butterknife btw D:
public class IngresoFragment extends Fragment {
@Bind(R.id.tilUsuario) TextInputLayout mTilUsuario;
@Bind(R.id.tilPassword) TextInputLayout mTilPassword;
@Bind(R.id.btnIngresar) Button btnIngresar;
@Bind(R.id.tviLibre) TextView tviLibre;
public IngresoFragment() {
// Required empty public constructor
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_ingreso, container, false);
ButterKnife.bind(this,view);
return view;
}
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
app();
}
void app(){
mTilUsuario.setHint(getResources().getString(R.string.usuario));
mTilPassword.setHint(getResources().getString(R.string.password));
events();
}
void events(){
btnIngresar.setOnClickListener(new View.OnClickListener() {
String usuario = mTilUsuario.getEditText().getText().toString().trim();
String password = mTilPassword.getEditText().getText().toString().trim();
@Override
public void onClick(View v) {
Toast.makeText(getActivity(), usuario, Toast.LENGTH_LONG).show();
}
});
}