繁体   English   中英

如何通过将其放入包中来访问android活动中的java类?

[英]how to access java class in android activity from putting it in a package?

我通过在另一个包中使用java类创建函数来在方法中调用它。

 private void drawRegressionLine() {

    //Toast.makeText(MainActivity.this, "Regression line view ", Toast.LENGTH_SHORT).show();

    ArrayList<String> point = new ArrayList<String>();

    Algorithm algorithm = new MaxLikelihood() {

    point = c.KNN(point);
    plot(point);
    };`
package firstpackagename;
import secondpackagename.*; /*add other necessary imports*/
public class MainActivity extends Activity {@
    Override public void onCreate(Bundle s) {
        super.onCreate(s);
        TheClassInOtherPackage X = new TheClassInOtherPackage(); /*If empty constructor used*/
        Object o = X.methodInOtherpackage(params1, params2, ....); /*Replace this with X.methodInOtherpackage(...) if method returns voids. Replace object o with the proper return type*/
    }
}

注意-您也可以通过向构造函数添加返回类型来返回值,就像方法一样。 希望这可以帮助。 :)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM