how to do two operations from a single click of a button in android

邮差的信 提交于 2019-12-13 06:55:34

问题


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.



来源:https://stackoverflow.com/questions/5323243/how-to-do-two-operations-from-a-single-click-of-a-button-in-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!