如何从java中的匿名内部类返回对象

时间:2013-08-30 15:24:19

标签: java android function anonymous-inner-class

如果我有以下功能:

        public class Product {

    public String barCode;
    public String name;
    public Category category;
    public double price;
    public Store store;
    WebService ws = new WebService();

    public product getProduct(String barcode) {

        final Product p = new Product();
        ParseQuery<ParseObject> query = ParseQuery.getQuery("Product");
        query.getInBackground("XxfqN425pK", new GetCallback<ParseObject>() {
            public void done(ParseObject object, ParseException e) {
                if (e == null) {
                    Log.d("((((( name )))))", name);

                    String name1 = "p=" + object.getString("product_name");
                    p.name = name1;

                } else {
                    p.name = "erro" + e.getMessage();

                }
            }
        });
        return p;

    }

    public Product get() {
        return this;
    }

}

p.name来自getProduct()调用的Log始终为空,尽管@Override protected Product doInBackground(Void... arg0) { Product p = new Product(); return p.getProduct(""); } @Override protected void onPostExecute(Product result) { // TODO Auto-generated method stub super.onPostExecute(result); Log.d("Product name >>>", result.name + "--"); } 语句显示名称的值

在哪里调用函数:

class getProduct扩展了AsyncTask {

{{1}}

}

0 个答案:

没有答案