我AutoCompleteTextView
通过使用onTextChanged
在文本更改时调用api来建议存储在MySQL数据库中的地名。响应是JSON数组,包含许多项,如place_name,id,location_key,query_type,request_type等(每个项目都有不同的用途)。我有3个隐藏的EditText字段。在setOnItemClickListener
,当用户选择地名时,我希望这3个隐藏字段的值自动设置为location_key,query_type和request_type,因为我需要使用地名发送这3个值以获取所需的结果API。
答案 0 :(得分:0)
单击place_name字段后,隐藏的EditTexts应获取您需要发送到数据库的值。通过执行以下操作可以轻松获得此信息:
textMessage.addTextChangedListener(new TextWatcher(){
public void afterTextChanged(Editable s) {
if (textMessage == "//Name of place") {
editText1.setText "//whatever you need";
editText2.setText "//whatever you need";
editText3.setText "//whatever you need";
}
}
});
或者,我会使用微调器作为地名,并使用与此类似的代码对其进行编码:
@覆盖 public void onClick(查看arg0){
int range = spnDonate.getSelectedItemPosition();
Donator_Name = tboxName.getText().toString();
switch(range) {
case 0:
editText1.setText = "//whatever you need";
editText2.setText = "//whatever you need";
editText3.setText = "//whatever you need";
break;
case 1:
editText1.setText = "//whatever you need";
editText2.setText = "//whatever you need";
editText3.setText = "//whatever you need";
break;
case 2:
editText1.setText = "//whatever you need";
editText2.setText = "//whatever you need";
editText3.setText = "//whatever you need";
break;
}
}
希望这会有所帮助:)
答案 1 :(得分:-1)
将这些字段的可见性设置为已消失。
txtview.setVisibility(View.GONE);
当你想让它们可见时使用
txtPromo.setVisibility(View.VISIBLE);