خرید بک لینک

Vote count: 0

I have a assignment for university, I have started it and have made some good progress but, now I have come to a standstill and [don't] know what to do. I will attach the assignment specs as a image1 and I will also add what code I have at the moment.

My code so far: ( Thank you for help in advance)

import android.content.Context;
import android.graphics.Color;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.StrictMode;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.TableLayout;
import android.widget.TableRow;
import android.widget.TextView;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.lang.reflect.Array;
import java.net.HttpURLCoection;
import java.net.URL;
import java.nio.charset.MalformedInputException;
import java.util.ArrayList;

public class MainActivity extends AppCompatActivity {

    double lat = 0; // Keep lat as 0 as it will be altered later on
    double lon = 0; // Keep lon as 0 as it will be altered later on

    @Override
    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
        StrictMode.setThreadPolicy(policy);

        Context context = this.getApplicationContext();
        LocationManager locMan = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
        try { //Surround code in a try/catch so if there is something wrong a error will be shown rather than the whole app crashing
            locMan.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, new LocationListener() {
                        @Override
                        public void onLocationChanged(Location location) {
                            lat = location.getLatitude();
                            lon = location.getLongitude();

                        }

                        public void onStatusChanged(String provider, int status, Bundle extras) {

                        }

                        @Override
                        public void onProviderEnabled(String provider) {

                        }

                        @Override
                        public void onProviderDisabled(String provider) {

                        }
                    }
            );
        } catch (SecurityException se) { // Catch statement containing a  security exception

        }
    }
    public void Location_Onclick (View v){

        ArrayList<String> listItems = new ArrayList<>(); // Create a new array list with all of the locations within

        try{
            URL Office = new URL("http://sandbox.kriswelsh.com/hygieneapi/hygiene.php?op=s_loc&lat=53.472128&long=-2.239928"); // The url in which the locations are taken from
            HttpURLCoection OC = (HttpURLCoection) Office.openCoection(); // Create & Open A Http URL Coection
            InputStreamReader isr = new InputStreamReader(OC.getInputStream()); // Create & Allow A Input Stream Reader
            BufferedReader in = new BufferedReader(isr); // Create & Allow A Buffered Reader

            String line;
            while ((line = in.readLine()) != null){
                JSONArray ja = new JSONArray(line);
                for (int i = 0; 1 < ja.length(); i++) {
                    JSONObject result = (JSONObject) ja.get(i);

                    TableLayout Table = (TableLayout) findViewById(R.id.Table); // Create a new table layout
                    TextView TV = new TextView(getApplicationContext()); // Create a text view
                    TextView TV2 = new TextView(getApplicationContext()); // Create a text view
                    TextView TV3 = new TextView(getApplicationContext()); // Create a text view
                    TextView TV4 = new TextView(getApplicationContext()); // Create a text view
                    TextView TV5 = new TextView(getApplicationContext()); // Create a text view
                    TextView TV6 = new TextView(getApplicationContext()); // Create a text view
                    TV.setTextColor(Color.BLACK); // Set text view's text to black
                    TV2.setTextColor(Color.BLACK); // Set text view's text to black
                    TV3.setTextColor(Color.BLACK); // Set text view's text to black
                    TV4.setTextColor(Color.BLACK); // Set text view's text to black
                    TV5.setTextColor(Color.BLACK); // Set text view's text to black
                    TV6.setTextColor(Color.BLACK); // Set text view's text to black
                    TV.setText(result.getString("BusinessName")); // First text view will contain 'Business Name'
                    TV2.setText(result.getString("RatingValue")); // Second text view will contain 'Rating Value'
                    TV3.setText(result.getString("AddressLine1")); // Third text view will contain 'Address Line 1'
                    TV4.setText(result.getString("AddressLine2")); // Fourth text view will contain 'Address Line 2'
                    TV5.setText(result.getString("AddressLine3")); // Fifth text view will contain 'Address Line 3'
                    TV6.setText(result.getString("PostCode")); // Sixth text view will contain 'Post Code'
                    TableRow TR = new TableRow(getApplicationContext()); // Add a new table row
                    TR.addView(TV); // Text view to add a row
                    TR.addView(TV2); // Text view 2 to add a row
                    TR.addView(TV3); // Text view 3 to add a row
                    TR.addView(TV4); // Text view 4 to add a row
                    TR.addView(TV5); // Text view 5 to add a row
                    TR.addView(TV6); // Text view 6 to add a row
                    Table.addView(TR);
                }

            }
        }
        catch (MalformedInputException e) {e.printStackTrace();} // Catch statement containing a  Malformed Input exception
        catch (IOException e) {e.printStackTrace();} // Catch statement containing a IO exception
        catch (JSONException e) {e.printStackTrace();} // Catch statement containing a  JSON exception
    }
}

asked 1 min ago

برچسب: نویسنده: استخدام کار تاريخ: يکشنبه 15 فروردين 1395 ساعت: 18:15

صفحه بندی