mdsami / android-query

Automatically exported from code.google.com/p/android-query
0 stars 0 forks source link

Setting text Doesn't work inside JSON CallBack #21

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago

public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        AQuery aq = new AQuery(this);   
        aq.id(R.id.text).text("TESTing");//works...
        String url = "http://function.com/json/url";             
        aq.ajax(url, JSONObject.class, this, "jsonCallback");
    }
public void jsonCallback(String url, JSONObject json, AjaxStatus status){
Log.i("test", "point 1");//gets called...
            aq.id(R.id.text).text("TESTing MORE");//fails, doesnt happen
Log.i("test", "point 2");//does not get called...
    }

What is the expected output? What do you see instead?
The above code should change R.id.text to "testing", followed by "testing more" 
once the json request is complete. It hsould also print "point 1" and "point 2" 
to logcat

What version of the product are you using? On what operating system?
0.18.5

Please provide any additional information below.

Original issue reported on code.google.com by Rob.Isak...@gmail.com on 16 Jan 2012 at 10:18

GoogleCodeExporter commented 8 years ago
I should also mention that I am using ActionBarSherlock, and building for 4.0.

Original comment by Rob.Isak...@gmail.com on 16 Jan 2012 at 10:18

GoogleCodeExporter commented 8 years ago
It works ok for me. In your code, the "aq" you created in onCreate is not in 
the scope for the "aq.id()" in your jsonCallback method. Is it possible that 
it's using a different "aq"?

Here's the code I tested with:

public class AdhocActivity extends Activity {

    private AQuery aq;

    @Override
    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);

        setContentView(R.layout.adhoc_activity);

        aq = new AQuery(this);

        aq.id(R.id.text).text("point 1");

        work();

    }

    private void work(){

        Log.i("test", "point 1");

        String url = "http://www.google.com/uds/GnewsSearch?q=Obama&v=1.0";
        aq.ajax(url, JSONObject.class, this, "jsonCb");

    }

    public void jsonCb(String url, JSONObject jo, AjaxStatus status){

        Log.i("test", "point 2");

        aq.id(R.id.text).text("point 2");

    }

}

Original comment by tinyeeliu@gmail.com on 31 Jan 2012 at 2:24

GoogleCodeExporter commented 8 years ago
Thanks for looking int othis, I had discovered the issue (improper scope) but 
forgot to come back here and mark it.   That's what I get for posting at 3am...

Original comment by Rob.Isak...@gmail.com on 31 Jan 2012 at 4:28