开发者

Call webservices in android on textchanged listener on one edit text and populate another edittext

I am able to call webservices now.

But In my project i want to populate the name of sponser corresponding to the sponser id .

For doing this I want to call a webservice on text changed listener of sponserid edittext o开发者_如何学编程r i have to monitor the focus changed of edittext.

Please guide me how to call webservice and populate another edittext.

Should i take keyevent ???

The codes i have tried so far are :

txtSpnID.setFocusable(true);
        if(txtSpnID.isFocused()){
            Log.v("TAG", "focus is on txtspid");
        }else{
            Log.v("TAG", "focus lost from txtspid");
        }

This prints focus lost from txtspid on logcat.

if(txtSpnID.hasFocus()){
            Log.v("TAG", "focus is on txtspid");
        }else{
            Log.v("TAG", "focus lost from txtspid");
        }

this also prints the same

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) {

                    }
                }
            }
        });

this prints corresponding logs on logcat but it does not show toast :( please help me guys


you just made Toast ... but you did'nt show it ... use Toast.show() like this Toast.makeToast(.....).show();

.... remeber to call web service in different thread(to prevent ANR)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜