【问题标题】:Call webservices in android on textchanged listener on one edit text and populate another edittext在一个编辑文本上的 textchanged 侦听器上调用 android 中的 web 服务并填充另一个编辑文本
【发布时间】: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)

标签: android android-edittext


【解决方案1】:

你刚刚做了吐司……但你没有展示它……像这样使用Toast.show()Toast.makeToast(.....).show();

....记得在不同的线程中调用 Web 服务(以防止 ANR)

【讨论】:

  • 是的,我在吐司中错过了一件愚蠢的事情,但现在告诉我应该创建一个函数来调用 web 服务并在此处调用该函数吗??
猜你喜欢
  • 2018-11-08
  • 1970-01-01
  • 2012-06-11
  • 1970-01-01
  • 1970-01-01
  • 2018-06-11
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多