【发布时间】:2015-09-02 17:19:21
【问题描述】:
我现在可以调用网络服务了。
但在我的项目中,我想填充与赞助商 ID 相对应的赞助商名称。
为此,我想在 sponserid edittext 的文本更改侦听器上调用 web 服务,或者我必须监视 edittext 的焦点更改。
请指导我如何调用网络服务并填充另一个编辑文本。
我应该参加 keyevent 吗???
到目前为止我尝试过的代码是:
txtSpnID.setFocusable(true);
if(txtSpnID.isFocused()){
Log.v("TAG", "focus is on txtspid");
}else{
Log.v("TAG", "focus lost from txtspid");
}
这会在 logcat 上打印从 txtspid 丢失的焦点。
if(txtSpnID.hasFocus()){
Log.v("TAG", "focus is on txtspid");
}else{
Log.v("TAG", "focus lost from txtspid");
}
这也打印相同的
txtSpnID.addTextChangedListener(new TextWatcher() {
@Override
public void onTextChanged(CharSequence arg0, int arg1, int arg2,
int arg3) {
// TODO Auto-generated method stub
Log.v("textfield","On text changed");
}
@Override
public void beforeTextChanged(CharSequence arg0, int arg1,
int arg2, int arg3) {
// TODO Auto-generated method stub
Log.v("textfield","before text changed");
}
@Override
public void afterTextChanged(Editable arg0) {
// TODO Auto-generated method stub
Log.v("textfield text",txtSpnID.getText().toString());
Toast.makeText(Registration.this, "SponserID is"+txtSpnID.getText().toString(),
Toast.LENGTH_LONG);
if (txtSpnID.getText().length() == 0) {
Toast.makeText(Registration.this, "Enter SponserID ",
Toast.LENGTH_LONG);
} else {
String spnId = txtSpnID.getText().toString();
try {
//call webservice here and get response from the service
} catch (Exception e) {
}
}
}
});
这会在 logcat 上打印相应的日志 但它不显示吐司:( 请帮帮我
【问题讨论】:
-
Toast.makeText(...).**show()**;
-
....记得在不同的线程中调用 Web 服务(以防止 ANR)