TextView在调试时更新,但不是按钮

时间:2013-06-20 00:41:52

标签: textview android-appwidget android

当我调试时,TextView也会更新,只有2个值,然后停止。如果我运行应用程序,则不会打印任何内容。是否与上下文有关? 请帮忙。这是我的代码。

//ListViewWidget.java

    public class ListViewWidget extends AppWidgetProvider{

        public static String name="Initial text";
        public static Context mContext;
        public static RemoteViews updateViews;
        public static ComponentName thisWidget;
        FetchTask fetchTask=new FetchTask();

        @Override
        public void onUpdate(Context context, AppWidgetManager appWidgetManager,
                int[] appWidgetIds) {

            super.onUpdate(context, appWidgetManager, appWidgetIds);
            updateViews = new RemoteViews(context.getPackageName(), R.layout.list_layout);
            //updateViews.setTextViewText(R.id.text_view,name);
            thisWidget = new ComponentName(context, ListViewWidget.class);

            fetchTask.execute();
         AppWidgetManager.getInstance(context.getApplicationContext());
            //manager.updateAppWidget(thisWidget, updateViews);
            mContext = context;
        }

public static class FetchTask extends AsyncTask<URL,Integer,String> implements ServerRequestEnvironment{

//all network calls done 

protected String doInBackground(URL ... arg0){

        ServerThreadState m_state = ServerThreadState.Idle;
        int networkTimeoutMS = 0;
        Dispatchable2 request = new OpIdentityPreAuth(this, null);

        ServerRequest2 sr = (ServerRequest2) request;
        final NetworkTiming nt = sr.getNetworkTiming();

        nt.setDequeued();

        if ((!sr.isKilled()) && sr.isSuccess()) {
            m_state = ServerThreadState.Computing;
            //this processPreconditions do nothing
            sr.processPreconditions();
            sr.computeRequest();
            nt.setComputed();
        }

        if ((!sr.isKilled()) && sr.isSuccess() && sr.preconditionsSatisfied()) {

            m_state = ServerThreadState.Executing;
            sr.execute(networkTimeoutMS);

        }
        try {
            sr.parse(null, sr.replyString);
        } catch (ParserConfigurationException e) {
            e.printStackTrace();
        } catch (SAXException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }

        response=((OpIdentityPreAuth)sr).getResponse();
        accessToken=response.getAccessToken(); //token generated and received
        //end token retrieval



        LocalStoreSearchResp storeResponse=new LocalStoreSearchResp();

        OpLocalStoreSearch respObj=new OpLocalStoreSearch(Core.getSi(), request2, null);
        RestTemplate restTemplate = new RestTemplate();
        restTemplate.setRequestFactory(new HttpComponentsClientHttpRequestFactory(NetworkUtils.getHttpClient(request, 90000)));
        restTemplate.getMessageConverters().add(new FormHttpMessageConverter());
        restTemplate.getMessageConverters().add(new StringHttpMessageConverter());

        HttpEntity<String> entity = new HttpEntity<String>("", getRequestHeaders());

        ResponseEntity<String> httpResponse = restTemplate.exchange("https://api.paypal.com/v1/stores?view=local&lat=37.3754664&lng=-121.9239147&radius=50&count=20&start_id=1&country_code=US", HttpMethod.GET, entity, String.class);

        LocalStoreSearchResp store = new LocalStoreSearchResp();
        try {
            store= Utils.inflateJson(httpResponse.getBody(), LocalStoreSearchResp.class);
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        storeResponse=respObj.getResponse(); //storeResponse is empty
        //store=respObj.getResponse();
        Log.i("StoreTag","store:"+store); //store populated with stores



//the result to be passed and updated
        int i = new Random().nextInt(25);
    storeObject=store.getStores().getItems().get(i).getStore();

    name= storeObject.getName();
    Log.i("StoreTag","storeval:"+name); //returns name of item      

    return name;
}

protected void onPostExecute(String name) {
            // TODO Auto-generated method stub
            Intent intent=new Intent("android.appwidget.action.APPWIDGET_UPDATE");

            PendingIntent pendingIntent=PendingIntent.getBroadcast(mContext, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);

            Log.i("TagVAl:","PI-"+pendingIntent);
            updateViews.setTextViewText(R.id.text_view,name);
            updateViews.setOnClickPendingIntent(R.id.next, pendingIntent);

            AppWidgetManager manager = AppWidgetManager.getInstance(mContext);
            manager.updateAppWidget(thisWidget, updateViews);
        }

0 个答案:

没有答案