how to do two operations from a single click of a

2019-09-19 00:31发布

问题:

hi i have created an app. I already have a coding to find the latitude and longitude of a place. But in that coding i have button and when the button is clicked the values get displayed

In my app i have a button named start, when i click the button it moves over to a new page. In that page i have placed two layouts. In one layout i have placed some textview and edit text data with a ok button. In the other layout i have placed the coding of latitude and longitude.

Now when i click the start button the new page must get opened and at the same time the current latitude and longitude must get displayed.

pls give help me in performing both the operations in the same page.......

回答1:

You don't need AsyncTask. You just have to update your views with information you obtain in loadCoords();.

Try something like:

  Coords coords = loadCoords();
  super.onCreate(savedInstanceState);        
  setContentView(R.layout.add);
  t1 = (TextView) findViewById(R.id.t1);
  t1.setText(coords.getLatitude());

P.S. Just a point: Java Convention advices you to name methods in Camel Case, like this: loadCoords() - the first letter is always small.



回答2:

You can use a Toast message to display the latitude and longitude, and then should open another activity.The Toast will remain visible for a particular time, and you'll also get your activity opened.