在列表视图中显示多维数组中的行中的两列 - android

发布于 2024-10-30 09:45:28 字数 1265 浏览 0 评论 0原文

我已经尝试了一段时间,试图找到一种方法来实现这一点,但是却一无所获。让我声明一下,我对 java/android 开发相当陌生,所以请保持温柔。

我拥有的是一个多维数组,提供有关商店位置的信息,如下所示

static final String[][] coordinates = new String[][] {
    {"1","location_name", "managername","geo:geolocation?z=10" },
    {"2","location_name","managername","geo:geolocation?z=10" },
    {"3","location_name","managername","geo:geolocation?z=10" },
    {"4","location_name","managername","geo:geolocation?z=10" }

};

我想做的只是从每行数组中提取 LOCATION_NAME 和 MANAGERNAME,并使用此处描述的布局 xml 将其显示在列表视图中,http://android-developers.blogspot.com/2009/02/android-layout-tricks-1.html

我读到最好使用矩阵光标来实现这一点,但作为 java 开发的新手,我对如何去做这件事有点困惑。

有人有任何想法可以引导我朝正确的方向前进吗?

谢谢,瑞安

编辑:我应该注意,我决定改变为更简单的实现方法......至少现在是这样。现在,我只使用两个一维数组,一个用于 LOCATION_NAME,另一个用于 MANAGER_NAME。我正在使用链接中描述的 2 行布局。我遇到的问题是在 IconicAdapter 中。如何用单独的字符串填充每行的两个(内部)行?这就是我所拥有的,我知道这是错误的。

class IconicAdapter extends ArrayAdapter<String>{
   IconicAdapter(){
       super(about.this, R.layout.about_layout, R.id.title, locations);
       super(about.this, R.layout.about_layout, R.id.secondLine, managers);
   }

I've been trolling for some time now trying to find a way to implement this but have come up dry. Let me state that I am fairly new to java/android development so please be gentle.

What I have is a multidimensional array giving info about a store location like so

static final String[][] coordinates = new String[][] {
    {"1","location_name", "managername","geo:geolocation?z=10" },
    {"2","location_name","managername","geo:geolocation?z=10" },
    {"3","location_name","managername","geo:geolocation?z=10" },
    {"4","location_name","managername","geo:geolocation?z=10" }

};

What I am trying to do is just pull the LOCATION_NAME and MANAGERNAME from the array per row, and display it in a list view using the layout xml described here, http://android-developers.blogspot.com/2009/02/android-layout-tricks-1.html.

I was reading that it might be best to use the matrix cursor to implement this, but as being new to java development, i'm a bit confused as to how I'd go about doing this.

Anyone have any ideas that can guide me in the right direction?

Thanks, Ryan

EDIT: I should note, I decided to change to a simpler method of implemenation... as least for now. NOW, I am using just two single dimension arrays, one for LOCATION_NAME and one for MANAGER_NAME. I am using the 2 row layout described in the link. Where I am running into a snag is in the IconicAdapter. How to I fill both (inner) rows of each row with a separate string? This is what I have, which i know is wrong.

class IconicAdapter extends ArrayAdapter<String>{
   IconicAdapter(){
       super(about.this, R.layout.about_layout, R.id.title, locations);
       super(about.this, R.layout.about_layout, R.id.secondLine, managers);
   }

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

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

发布评论

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

评论(1

绝不服输 2024-11-06 09:45:28

您需要子类化ArrayAdapter并重写getView()这是我的一本书中的免费摘录,其中介绍了如何完成此操作。

You will need to subclass ArrayAdapter and override getView(). Here is a free excerpt from one of my books that covers how this is done.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文