尝试“逻辑”时遇到困难一些东西(还有语法/ArrayList帮助)

发布于 2024-10-27 13:43:06 字数 816 浏览 2 评论 0原文

所以,我正在为我的老板编写一个 Android 应用程序。目前,我们的工作方式是:

MainActivity.java 创建 User.java 对象。它只会创建其中 1 个。用户将存储有关该人(我们的客户)的信息。

用户对象将创建并填充帐户对象。一个用户可以拥有多个我们的应用程序必须知道的帐户。

帐户将创建并填充组对象。一个用户可以属于多个帐户内的多个组。

我现在通过在 MainActivity 中创建用户对象来完成此操作:

//empty constructor for testing 用户 usr = new User();

用户创建帐户对象并将它们存储在 ArrayList 中。这就是我的第一个问题出现的地方......我不太明白我想的语法......因为每当我调用类似的东西时:

index = 1-x; //无论我想要得到什么数字 System.out.println(accountarray.getacctname(accountarray.get(index)));

//上面应该在index处的accountarray索引上调用“获取帐户名称”。但是,它 // 似乎只返回最新的项目。

它似乎只返回最近添加的帐户对象?

Account 对象在 ArrayList 中创建和存储组,类似于 User 和 Account。

或者,我们有:

User --creates*-- Accounts -- create* -- Groups

Creates* == 创建并存储在 ArrayList 中。

有人有什么建议吗?具体来说,为什么它只返回最后一个对象?

So, I'm writing an android app for my boss. Currently, the way we have it work is:

MainActivity.java creates User.java objects. It will only ever create 1 of these. User will store information about the person (our customer).

User objects will create and populate Account objects. A user can have multiple accounts with us that our app has to be aware of.

Accounts will create and populate Group objects. A user can be in multiple groups within multiple accounts.

I'm doing it now by creating the user object in MainActivity as:

//empty constructor for testing
User usr = new User();

User creates account objects and stores them in an ArrayList. Here's where my first problem is coming in... I don't quite understand the syntax I suppose.. because whenever I call something like:

index = 1-x; //whatever number I want to get
System.out.println(accountarray.getacctname(accountarray.get(index)));

//The above should call "get account name" on the index of accountarray at index. However, it only //seems to return the most recent item.

it only seems to return the most recently-added account object?

Account objects create and store groups in ArrayLists, similar to User and Account.

Or, we have:

User --creates*-- Accounts -- creates* -- Groups

Creates* == creates and stores in an ArrayList.

Does anybody have any suggestions? Specifically, why is it only returning the last-in object?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

思慕 2024-11-03 13:43:06

查看ArrayList中所有条目的信息。

如果他们都说最新的内容,那么也许您忘记在某处添加“新”。

Look at the information of all the entries in the ArrayList.

If they all say what is in the most recent one, then maybe you forgot to put a "new" somewhere.

花开浅夏 2024-11-03 13:43:06

好的,这是一些相关代码。 subID 是“Account”类的名称。 “subids”是Account类的数组列表。让我知道是否有任何其他相关代码会有帮助。

    subID subs = new subID("1", "7939","1d", "1");
    subID subs0 = new subID("2", "7939","1dde", "1");
    subID subs1 = new subID("3", "791239","1dasd", "1");
    subID subs2 = new subID("4", "7933149","1dfdsa", "1");      
    subids.add(subs);
    subids.add(subs0);
    subids.add(subs1);
    subids.add(subs2);
    int index = 1;
    System.out.println(subids.get(index).getsubname());
    System.out.println(subids.get(subids.size()-1).getsubname()+"This should be the second to last entry");
    System.out.println(subids.size());

Alright, here's some of the relevant code. subID is the name of the "Account" class. "subids" is the array list of Account classes. Let me know if any other relevant code would be helpful.

    subID subs = new subID("1", "7939","1d", "1");
    subID subs0 = new subID("2", "7939","1dde", "1");
    subID subs1 = new subID("3", "791239","1dasd", "1");
    subID subs2 = new subID("4", "7933149","1dfdsa", "1");      
    subids.add(subs);
    subids.add(subs0);
    subids.add(subs1);
    subids.add(subs2);
    int index = 1;
    System.out.println(subids.get(index).getsubname());
    System.out.println(subids.get(subids.size()-1).getsubname()+"This should be the second to last entry");
    System.out.println(subids.size());
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文