gpt4 book ai didi

Android EditText 值不显示

转载 作者:行者123 更新时间:2023-11-30 01:20:30 25 4
gpt4 key购买 nike

我正在尝试从 EditTexts 中检索用户输入的值,但没有显示任何内容。这是我的代码

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;
}
}

Toast 确实显示了,但日志结果总是“aaaa”,输入的值没有显示。

如果有人能帮忙..谢谢:))

最佳答案

您的代码获取 "" 值,因为它在点击之前运行....

用它解决你的问题......

load.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Toast.makeText(getActivity(), "Clicked", Toast.LENGTH_SHORT).show();
s1 = cardnummer.getText().toString();
s2 = bannummer.getText().toString();
s3 = transfersolde.getText().toString();
Log.e("CARDNUMBER", "aaaa"+s1);
Log.e("BANNUMBER","aaaa"+s2);
Log.e("TRANSFERT","aaaa"+s3);
}
});

享受编码............

关于Android EditText 值不显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37185222/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com