0

Suppose I have two classes, one is the main class A and the other is the class that helps in processing results for A, class B.

Suppose in class A I take user input a1, and a2. Then I have to send these inputs to class B for processing, and with these inputs, B generates a result b1 and b2 (which are not related to a1 and a2 independently, but a1 and a2 together generate these two results). And since class A being the main class, has to access b1 and b2 to display the results.

我该如何做到这一点?

我目前正在开发一个使用. 我真的很想将处理部分移到另一个班级,但我遇到了问题。抱歉,我的 Java 基础不是那么好。有人可以帮忙吗?Distance-Matrix APIMainActivity.java

4

1 回答 1

0

如果AB是普通的 Java 类,那么我建议你做一个简单的MyResults类。

示例

class MyResults {
final String b1;
final String b2;
public MyResults(final String b1, final String b2) {
    this.b1 = b1;
    this.b2 = b2;
}
public String getB1() { return b1; }
public String getB2() { return b2; }

类的响应B应该是返回一个MyResults类。


Now, if classes A and B happen to be Android Activity classes (i.e. "class A extends Activity") then throw all this out the window and pass results through the Extras bundle to be received in A.onActivityResult(). Super easy and standard to do, but you'll have to look for an example.

于 2013-03-30T01:49:15.807 回答