传递数组从A级到B级 [英] Passing an array from class A to class B

查看:183
本文介绍了传递数组从A级到B级的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个数组类命名的地板,它包含的值类似以下内容:

I have an array named Floors in class A, it contains values something like the following:

  List<Point> manualpoint = new ArrayList<Point>();
  int[] manualpointx = {135,200,300,155,235,300};

比方说,我希望这些价值传递给B类,supposingly B类已经宣布的超视图

Let's say I wish to pass these values to class B, supposingly class B has already declared a superclass View

public class DrawView extends View implements OnTouchListener { 
    @Override
    public void onDraw(Canvas canvas) {
        //pass the values into this class
    }

}

我如何通过从A类的值到B?

How do i pass the values from class A to B?

推荐答案

您可以做这样的事情。

final class A
{
     private static int[] manualpointx = {135,200,300,155,235,300};
     private static List<Point> manualpoint = new ArrayList<Point>();

     public static int[] returnArray()
     {
          return(manualpointx);   
     }

     public static List<Point> returnList()         
     {
          return(manualpoint);
     }

}
public class DrawView extends View implements OnTouchListener
{ 
    @Override
    public void onDraw(Canvas canvas) 
    {
         //pass the values into this class
         int arr[]=A.returnArray();
         List<Point> list=A.returnList();
    }
}

如果你只需要非静态字段在你的类 A ,如果你只想使用非静态方法,你将不得不通过一个实例来访问它们类 A 从你的类 DrawView

If you need only non-static fields in your class A and if you just want to use non-static methods, you will have to access them via an instance of the class A from your class DrawView.

这篇关于传递数组从A级到B级的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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