更新AsyncTask

时间:2015-10-01 02:37:56

标签: android android-asynctask

我正在使用谷歌方向API来获取我的位置和附近地点之间的持续时间,并且它正在运行。但是,我在设置值onPostExecute.I中的持续时间值时遇到问题,试图使持续时间全局但它不起作用。顺便说一下,我的textview在ViewHolder课程中。

public class ParserTask extends AsyncTask<String, Integer, List<List<HashMap<String,String>>> >{
    	 
    	  String distance = "";
		     String duration = "";
      	// Parsing the data in non-ui thread    	
    		@Override
    		public List<List<HashMap<String, String>>> doInBackground(String... jsonData) {
    			
    			JSONObject jObject;	
    			List<List<HashMap<String, String>>> routes = null;			           
              
              try{
              	jObject = new JSONObject(jsonData[0]);
              	DirectionsJSONParser parser = new DirectionsJSONParser();
              	
              	// Starts parsing data
              	routes = parser.parse(jObject);    
              }catch(Exception e){
              	e.printStackTrace();
              }
              return routes;
    		}
    		
    		// Executes in UI thread, after the parsing process
    		@Override
    		public void onPostExecute(List<List<HashMap<String, String>>> result) {
    			/*ArrayList<LatLng> points = null;
    			PolylineOptions lineOptions = null;
    			MarkerOptions markerOptions = new MarkerOptions();*/
    			
    			
    		     
    			if(result.size()<1){
    				Toast.makeText(context, "No Points", Toast.LENGTH_SHORT).show();
    				return;
    			}
    				
    			
    			// Traversing through all the routes
    			for(int i=0;i<result.size();i++){
    				
    				
    				// Fetching i-th route
    				List<HashMap<String, String>> path = result.get(i);
    				
    				// Fetching all the points in i-th route
    				for(int j=0;j<path.size();j++){
    					HashMap<String,String> point = path.get(j);	
    					
    					if(j==0){	// Get distance from the list
    						distance = (String)point.get("distance");						
    						continue;
    					}else if(j==1){ // Get duration from the list
    						duration = (String)point.get("duration");
    						continue;
    					}
    							
    				}
    				
    				
    			}
    			
    			
    			//holder.val.setText("value"+duration);
    			Toast.makeText(context,"Duration:"+duration ,Toast.LENGTH_LONG).show();
    			
    			
    			
    		}			

0 个答案:

没有答案