Click here to Skip to main content
15,886,823 members
Home / Discussions / Android
   

Android

 
AnswerRe: Android Pin
David Crow4-Jun-16 16:01
David Crow4-Jun-16 16:01 
QuestionNew beginer to android Pin
hmanhha3-Jun-16 6:51
hmanhha3-Jun-16 6:51 
AnswerRe: New beginer to android Pin
David Crow3-Jun-16 10:28
David Crow3-Jun-16 10:28 
AnswerRe: New beginer to android Pin
Richard MacCutchan3-Jun-16 22:43
mveRichard MacCutchan3-Jun-16 22:43 
AnswerRe: New beginer to android Pin
AkhilSreekar19-Jun-16 9:41
AkhilSreekar19-Jun-16 9:41 
Questionhow to retrieve or get next item from json file when press click button listner Pin
ahmed_sa3-Jun-16 3:05
ahmed_sa3-Jun-16 3:05 
QuestionRe: how to retrieve or get next item from json file when press click button listner Pin
David Crow3-Jun-16 4:05
David Crow3-Jun-16 4:05 
AnswerRe: how to retrieve or get next item from json file when press click button listner Pin
ahmed_sa3-Jun-16 12:34
ahmed_sa3-Jun-16 12:34 
My code is
Java
protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_eating);
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);


        card1 = (LinearLayout) findViewById(R.id.card_one);
        card2 = (LinearLayout) findViewById(R.id.card_two);
        card3 = (LinearLayout) findViewById(R.id.card_three);

        tvTitle1 = (TextView) findViewById(R.id.tv_title1);
        tvTitle2 = (TextView) findViewById(R.id.tv_title2);
        tvTitle3 = (TextView) findViewById(R.id.tv_title3);

        tvDetails1 = (TextView) findViewById(R.id.tv_details1);
        tvDetails2 = (TextView) findViewById(R.id.tv_details2);
        tvDetails3 = (TextView) findViewById(R.id.tv_details3);

        //adding listeners
        card1.setonclickListener(this);
        card2.setonclickListener(this);
        card3.setonclickListener(this);

       // type = getIntent().getIntExtra("type", 1);

        FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
        fab.setonclickListener(new View.onclickListener() {
            @Override
            public void onclick(View view) {

                if (count < 3) {

                    new GetPlace().execute();
                }



            }
        });
    }




    class GetPlace extends AsyncTask<Void, Void, Void> {

        /**
         * Before starting background thread Show Progress Dialog
         */
        @Override
        protected void onPreExecute() {
            super.onPreExecute();
            pDialog = new ProgressDialog(EatingActivity.this);
            pDialog.setMessage("Picking an Item...");
            pDialog.setIndeterminate(false);
            pDialog.setCancelable(true);
//            pDialog.show();
        }

        /**
         * Getting product details in background thread
         */
        protected Void doInBackground(Void... args) {

            // updating UI from Background Thread
            try {
                // Building Parameters
                List<NameValuePair> dataList = new ArrayList<NameValuePair>();
                //dataList.add(new BasicNameValuePair("id", '"' + args[0] + '"'));

                // getting product details by making HTTP request
                // Note that product details url will use GET request
                JSONObject json = jsonParser.
                        makeHttpRequest(AppConfig.URL_GET_Place, "GET", dataList);


                // json success tag
                JSONObject meta = json.getJSONObject("meta");
                success = meta.getInt("code");
                JSONObject response = json.getJSONObject("response");
                JSONArray venues = response.getJSONArray("venues");

                for (int i = 0; i < venues.length(); i++) {
                    selectedPlace = new Place();
                    JSONObject object = venues.getJSONObject(i);
                    selectedPlace.setTitle(object.getString("name"));
                    selectedPlace.setId(object.getString("id"));
                    JSONObject location = object.getJSONObject("location");

                    JSONArray formattedAddress=location.getJSONArray("formattedAddress");
                    Log.d("length",formattedAddress.length()+"");
                    String currentLocation="";
                    for (int j=0;j<formattedAddress.length();j++)
                    {
                        currentLocation+=formattedAddress.getString(j)+", ";
                        Log.d("address",currentLocation);
                    }

                    selectedPlace.setAddress(currentLocation);
                    selectedPlace.setLat(location.getDouble("lat"));
                    selectedPlace.setLng(location.getDouble("lng"));
                    Log.d("name", selectedPlace.getTitle());
                    places.add(selectedPlace);
                }

            } catch (JSONException e) {
                e.printStackTrace();
            }

            return null;
        }


        /**
         * After completing background task Dismiss the progress dialog
         **/
        protected void onPostExecute(Void args) {
            // dismiss the dialog once got all details
            if (!pDialog.isShowing()) {
                pDialog.dismiss();
                if (success == 200) {

                    if (count == 0) {
                        card1.setVisibility(View.VISIBLE);
                        tvTitle1.setText(places.get(count).getTitle());
                        tvDetails1.setText(places.get(count).getAddress());
                    } else if (count == 1) {
                        card2.setVisibility(View.VISIBLE);
                        tvTitle2.setText(places.get(count).getTitle());
                        tvDetails2.setText(places.get(count).getAddress());
                    } else if (count == 2) {
                        card3.setVisibility(View.VISIBLE);
                        tvTitle3.setText(places.get(count).getTitle());
                        tvDetails3.setText(places.get(count).getAddress());
                    }
                    count++;
                } else {
                    Toast.makeText(EatingActivity.this, "Couldn't find any nearby places", Toast.LENGTH_LONG).show();

                }
            }
        }
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        return super.onCreateOptionsMenu(menu);
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {

        if (item.getItemId() == android.R.id.home)
            finish();
        return super.onOptionsItemSelected(item);
    }

    @Override
    public void onclick(View view) {
        int index = 0;


            if (view.getId() == card1.getId()) {
                index = 0;
            } else if (view.getId() == card2.getId()) {
                index = 1;
            } else if (view.getId() == card3.getId()) {
                index = 2;
            }

            String strUri = "http://maps.google.com/maps?q=loc:"
                    + places.get(index).getLat() + "," + places.get(index).getLng() +
                    "(" + places.get(index).getTitle() + ")";
            Log.d("url",strUri);
            Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(strUri));
            startActivity(intent);



    }
}

GeneralRe: how to retrieve or get next item from json file when press click button listner Pin
ahmed_sa3-Jun-16 13:08
ahmed_sa3-Jun-16 13:08 
SuggestionRe: how to retrieve or get next item from json file when press click button listner Pin
Richard MacCutchan3-Jun-16 22:42
mveRichard MacCutchan3-Jun-16 22:42 
GeneralRe: how to retrieve or get next item from json file when press click button listner Pin
ahmed_sa4-Jun-16 1:02
ahmed_sa4-Jun-16 1:02 
GeneralRe: how to retrieve or get next item from json file when press click button listner Pin
Richard MacCutchan4-Jun-16 1:06
mveRichard MacCutchan4-Jun-16 1:06 
GeneralRe: how to retrieve or get next item from json file when press click button listner Pin
David Crow4-Jun-16 3:16
David Crow4-Jun-16 3:16 
QuestionRe: how to retrieve or get next item from json file when press click button listner Pin
David Crow4-Jun-16 3:16
David Crow4-Jun-16 3:16 
AnswerRe: how to retrieve or get next item from json file when press click button listner Pin
ahmed_sa4-Jun-16 11:24
ahmed_sa4-Jun-16 11:24 
QuestionHow to resize layouts by swiping up and down Pin
jasonalien1-Jun-16 6:45
jasonalien1-Jun-16 6:45 
AnswerRe: How to resize layouts by swiping up and down Pin
Richard MacCutchan1-Jun-16 7:11
mveRichard MacCutchan1-Jun-16 7:11 
GeneralRe: How to resize layouts by swiping up and down Pin
jasonalien1-Jun-16 7:25
jasonalien1-Jun-16 7:25 
GeneralRe: How to resize layouts by swiping up and down Pin
Richard MacCutchan1-Jun-16 21:03
mveRichard MacCutchan1-Jun-16 21:03 
GeneralRe: How to resize layouts by swiping up and down Pin
jasonalien1-Jun-16 22:19
jasonalien1-Jun-16 22:19 
QuestionRe: How to resize layouts by swiping up and down Pin
David Crow2-Jun-16 4:28
David Crow2-Jun-16 4:28 
QuestionOnkeyDown Event in Xamarin Forms Pin
Srinivas Soodula31-May-16 2:06
Srinivas Soodula31-May-16 2:06 
QuestionGet error when passing data using Intent Pin
tan87325-May-16 21:15
tan87325-May-16 21:15 
SuggestionRe: Get error when passing data using Intent Pin
Richard Deeming26-May-16 2:08
mveRichard Deeming26-May-16 2:08 
QuestionRe: Get error when passing data using Intent Pin
David Crow26-May-16 4:29
David Crow26-May-16 4:29 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.