从另一个班级返还双倍的最简单方法 [英] Easiest way to return double from another class

查看:71
本文介绍了从另一个班级返还双倍的最简单方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望根据输入的双精度数从另一个类返回一个双精度数。
任何非常简单的项目结构示例的好的链接/示例,将不胜感激。
我在清单中缺少什么吗?

活动1

I wish to return a double from another class depending on input doubles. Any good links/examples to very simple project structure examples would be appreciated. Am I missing something in manifest. ie. activity 1

import com.example.app.utils.getRhumbLineBearingUtil;


double tbearing =             getRhumbLineBearing(alata,alona,alatb,alonb);

double recipbearing=getRhumbLineBearing(alatb, alonb, alata, alona);

活动2
import com.example.app.utils.getRhumbLineBearingUtil;

Activity 2 import com.example.app.utils.getRhumbLineBearingUtil;

 double lattocbearing = getRhumbLineBearing(lat,lon,alatc,alonc);

 double bcbearing=getRhumbLineBearing(alatb, alonb, alatc, alonc);

(我在许多具有15种不同收益的活动中进行了此操作,其中一些输入即gps点快速变化)

(I do this over many activities with 15 different returns with some inputs ie gps points changing rapidly)

Class
包com.example.app.utils;

Class package com.example.app.utils;

public class getRhumbLineBearingUtil
{


public double getRhumbLineBearing(double $lat1, double $lon1, double $lat2, double $lon2)
  {Yada=trueRhumb  ;
double Bearing=yada;
Return (bearing);
      }
}

我对bearb并没有兴趣

I am not interested in bearingTo which is the initial bearing hearing.

推荐答案

您应该首先学习一些Java编程,然后再学习android。你不能那样做。试试这个:

You should first learn a bit of Java programming and then move-up to android. You cannot do that that way. Try this:

Class GetRhumbLineBearingUtil {    

    public static double getRhumbLineBearing(double lat1, double lon1, double lat2, double lon2) {
        return lat1 + lon1;
    }
}

然后在另一个类中,在导入之后,无论要使用该方法,只需像这样调用它:

And then in another class, after import and whatever you wanna use that method for, just call it like this:

double lattocbearing = GetRhumbLineBearingUtil.getRhumbLineBearing(alatb, alonb, alata, alona);

此处有一些注意事项:可以通过ClassName.methodName

Some notes here: static methods can be accessed via ClassName.methodName

这是我从问题中了解的内容。现在,如果您想在活动之间交换数据,那就是另一回事了,您可以使用意图。

This was what i understood from the question. Now if you want to exchange data between activities, then that is another story, you can use intents.

一些注意事项:


  • 类名以upperCase开头

  • 类,方法和方法参数应具有正确的名称/含义,以使其更容易理解所包含的内容

  • 变量名以小写开头

  • Java中没有 $ variable 通过值传递

  • 如果要返回存储在类 GetRhumbLineBearingUtil 中的变量中的某些值,则需要将该变量设置为静态很好。

  • Class names start with upperCase
  • Classes, methods and method arguments should have a proper name/meaning to make it easier to understand what is being done.
  • Variable names start lowerCase
  • There is no $variable in Java, everything is passed by value
  • If you want to return some value stored in a variable in class GetRhumbLineBearingUtil you need to make that variables static as well.

这篇关于从另一个班级返还双倍的最简单方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆