Java Android app. Loading all info from DB but only Display Certain ones

thuchewerge

New Member
OK so for a while i have been getting "names" and "location" from the DB and listing them in a table.one after an other using a loop untill its all displayed there are 22 in all. for example.name 1 | location 1name 2 | location 2 name 3 | location 3What i want to is no load the info in background as i already am but only pick the data when its needed, so i can have pictures txt then the data. for example.{Picture} {Picture}{txt}{name 1} {txt}{name 2}instead of it just all being listed one after another to make the page smarter looking. BTW this is a Results page for my Formula 1 app.GetDataFromDB2.java ------\[code\]package com.test.test;import org.apache.http.client.HttpClient;import org.apache.http.client.ResponseHandler;import org.apache.http.client.methods.HttpPost;import org.apache.http.impl.client.BasicResponseHandler;import org.apache.http.impl.client.DefaultHttpClient;public class GetDataFromDB2 {public String getDataFromDB() { try { HttpPost httppost; HttpClient httpclient; httpclient = new DefaultHttpClient(); httppost = new HttpPost( "http://192.168.1.69/GetResults.php"); // change this to your URL..... ResponseHandler<String> responseHandler = new BasicResponseHandler(); final String response = httpclient.execute(httppost, responseHandler); return response.trim(); } catch (Exception e) { System.out.println("ERROR : " + e.getMessage()); return "error"; }}}\[/code\]This is the desplayed Results.java\[code\]package com.test.test;import java.util.ArrayList;import java.util.Iterator;import org.json.JSONArray;import org.json.JSONException;import org.json.JSONObject;import android.app.Activity;import android. graphics. Color;import android.os.Bundle;import android.util.Log;import android.view.View;import android.widget.FrameLayout;import android.widget.LinearLayout;import android.widget.TableLayout;import android.widget.TableRow;import android.widget.TableRow.LayoutParams;import android.widget.TextView;public class Results extends Activity {String datahttp://stackoverflow.com/questions/15877108/= "";TableLayout tl;TableRow tr;TextView label;@Overridepublic void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.results); tl = (TableLayout) findViewById(R.id.maintable); final GetDataFromDB2 getdb = new GetDataFromDB2(); new Thread(new Runnable() { public void run() { data = http://stackoverflow.com/questions/15877108/getdb.getDataFromDB(); System.out.println(data); runOnUiThread(new Runnable() { @Override public void run() { ArrayList<Users> users = parseJSON(data); addData(users); } }); } }).start();}public ArrayList<Users> parseJSON(String result) { ArrayList<Users> users = new ArrayList<Users>(); try { JSONArray jArray = new JSONArray(result); for (int i = 0; i < jArray.length(); i++) { JSONObject json_data = jArray.getJSONObject(i); Users user = new Users(); user.setId(json_data.getInt("idresults")); user.setName(json_data.getString("driver")); user.setPlace(json_data.getString("local")); users.add(user); } } catch (JSONException e) { Log.e("log_tag", "Error parsing data " + e.toString()); } return users;}void addHeader(){ /** Create a TableRow dynamically **/ tr = new TableRow(this); /** Creating a TextView1 to add to the row **/ label = new TextView(this); label.setText("DRIVERS"); label.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)); label.setPadding(20, 5, 5, 5); label.setBackgroundColor(Color.argb(255, 25, 25, 25)); label.setTextColor(Color.argb(-19, 246, 255, 0)); LinearLayout Ll = new LinearLayout(this); LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT); params.setMargins(0, 0, 0, 0); //Ll.setPadding(10, 5, 5, 5); Ll.addView(label,params); tr.addView((View)Ll); // Adding textView to tablerow. /** Creating textview2 Button **/ TextView place = new TextView(this); place.setText("GRAND PRIX"); place.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)); place.setPadding(20, 5, 5, 5); place.setBackgroundColor(Color.argb(255, 25, 25, 25)); place.setTextColor(Color.argb(-19, 246, 255, 0)); Ll = new LinearLayout(this); params = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT); params.setMargins(0, 0, 0, 0); //Ll.setPadding(10, 5, 5, 5); Ll.addView(place,params); tr.addView((View)Ll); // Adding textview to tablerow. // Add the TableRow to the TableLayout tl.addView(tr, new TableLayout.LayoutParams( LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));}@SuppressWarnings({ "rawtypes" })public void addData(ArrayList<Users> users) { addHeader(); for (Iterator i = users.iterator(); i.hasNext();) { Users p = (Users) i.next(); /** Create a TableRow dynamically **/ tr = new TableRow(this); /** Creating a TextView to add to the row **/ label = new TextView(this); label.setText(p.getName()); label.setId(p.getId()); label.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)); label.setPadding(20, 5, 5, 5); label.setBackgroundColor(Color.argb(255, 25, 25, 25)); label.setTextColor(Color.argb(255, 0, 198, 255)); LinearLayout Ll = new LinearLayout(this); LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT); params.setMargins(0, 1, 1, 0); //Ll.setPadding(10, 5, 5, 5); Ll.addView(label,params); tr.addView((View)Ll); // Adding textView to tablerow. /** Creating Qty Button **/ TextView place = new TextView(this); place.setText(p.getPlace()); place.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)); place.setPadding(20, 5, 5, 5); place.setBackgroundColor(Color.argb(255, 25, 25, 25)); place.setTextColor(Color.argb(255, 0, 198, 255)); Ll = new LinearLayout(this); params = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT); params.setMargins(0, 1, 1, 0); //Ll.setPadding(10, 5, 5, 5); Ll.addView(place,params); tr.addView((View)Ll); // Adding textview to tablerow. // Add the TableRow to the TableLayout tl.addView(tr, new TableLayout.LayoutParams( LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT)); }}}\[/code\]If you can figure it out you will see this Creates its own table and lays them out. all i want is to use the data at cirtain times in the page. ps each database entry as a "id" with them for example ID - 1. name 1. location 1. id - 2. name 2. locations 2 the id is just 1 - 22 would it be easyer using the id ?
 
Top