我試圖從EditTexts檢索用戶輸入的值,但沒有顯示出來。這裏是我的代碼Android EditText值不顯示
public class RechargeCarte extends Fragment {
private EditText cardnummer,transfersolde,bannummer;
RequestQueue requestQueue;
String s1,s2,s3;
public RechargeCarte() {
// Required empty public constructor
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_recharge_carte, container, false);
final Button load = (Button) rootView.findViewById(R.id.btn_load_card);
cardnummer = (EditText) rootView.findViewById(R.id.et_card_number);
transfersolde = (EditText) rootView.findViewById(R.id.et_transfer_solde);
bannummer = (EditText) rootView.findViewById(R.id.et_ban_number);
requestQueue = Volley.newRequestQueue(getActivity());
s1 = cardnummer.getText().toString();
s2 = bannummer.getText().toString();
s3 = transfersolde.getText().toString();
load.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Toast.makeText(getActivity(), "Clicked", Toast.LENGTH_SHORT).show();
Log.e("CARDNUMBER", "aaaa"+s1);
Log.e("BANNUMBER","aaaa"+s2);
Log.e("TRANSFERT","aaaa"+s3);
}
});
return rootView;
}
}
敬酒不出現,但日誌結果總是「AAAA」所輸入的值顯示不出來。
如果任何人可以幫助..謝謝:))
從裏面的EditText''的onClick方法獲得的輸入值。如果您在'onCreateView'內調用'getText'方法,那麼它將返回空字符串而不是用戶輸入的字符串。 –
它並沒有真正有所作爲,但是您希望將「Log.d」用於這些類型的日誌記錄。 –