• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps onPostExecute only showing last row of data in TextView? Pulled from server.

RED_

Well-Known Member
Hey all, as the title says; I have data being pulled from a mySQL database on a remote server. I'm using AsyncTask to do this in the background. Anyway the issue comes when I try and display the data that has just been pulled. There are 24 rows and when I put set up the TextView it only displays the last row.

I've added some logs to tell me where the issue is and it's being very weird, there is no issue when I parse the data. The log shows all 24 rows just fine, but when I see the log in the onPostExecute it only shows the last row.

Here is the code:

Code:
// PARSE STRING TO JSON
	        try {
	            jArray = new JSONArray(result);
	            JSONObject json_data = null;
	          	            
	            for (int i = 0; i < jArray.length(); i++) { 
	       	        
	            	
	            	json_data = jArray.getJSONObject(i);
	            	drivername = json_data.getString("Driver_full_name");
	            	Log.i("This log shows all data", drivername);
	            	
	            }
	            
	        } catch (JSONException e1) {
	            Log.d("DB", "Error somewhere");
	            CurrentSeasonDrivers.this.runOnUiThread(new Runnable() { 
            		public void run() {
            			Toast.makeText(CurrentSeasonDrivers, "Could not parse data so shut up", Toast.LENGTH_LONG).show(); } });
	        }
		
			return drivername;	
			}
		
		protected void onPostExecute(String drivername){
			
			Log.i("This log only shows the last row", drivername);
			TextView something = (TextView) findViewById(R.id.DriverName);
			something.setText(something.getText() + "\n" + drivername);
			Toast.makeText(CurrentSeasonDrivers, "DONE!", Toast.LENGTH_LONG).show();
			
		}	
	}

Something between the first log (the one within the for loop) and the second (in the onPostExecute) is causing it to remove all other rows. The bit of code there has no bearing on it though which is weird.

Someone noted that there is chance that the TextView is overwriting the data with the row below and therefore by the end of it I'm only being left with the last row. How would I stop this though?

I would really appreciate it any advice. Thanks.
 
Back
Top Bottom