Android的ListView控件:如何添加各种itens连续以动态的方式? [英] Android ListView: how to add various itens in a row in a dynamic way?

查看:125
本文介绍了Android的ListView控件:如何添加各种itens连续以动态的方式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要在如何完成一项任务的一些技巧。

I want some tips in how to complete one task.

我们有三个EditTexts,一个按钮和一个llistview。

We got three EditTexts, a button and a llistview.

这里的想法是当按钮pressed,从三EditTexts文本将显示在列表视图,相映成趣,给人IM pression,我们得到了一个表在这里。

The idea here is when the button is pressed, the texts from the three EditTexts will be show in a listview, side by side, giving the impression that we got a table here.

这里的问题是我不知道该怎么做。我试着在网上搜索一些东西,但我什么也没得到。

The problem here is I don't know how to do it. I've tried to search something on the net, but I just got nothing.

我真的AP preciate如果你能帮助。
对于关注Thaks,并有一个愉快的一天。

I'd really appreciate if you could help. Thaks for the attention and have a nice day.

推荐答案

有几种方法可以达到你想要的东西。如果我理解正确,您有一个列表视图和一个按钮。当你点击按钮,你要3 editTexts出现在并排的列表视图侧,使得它看起来像一个表。

There are a couple ways to achieve what you want. If I'm understanding correctly you have a listview and a button. When you click the button, you want 3 editTexts to appear in your listview side by side so that it looks like a table.

的最简单的解决方案是有你的列表项的布局,在listadapter充气,简单地用weightSum含有3 edittexts与layout_weight一个的LinearLayout =3=1和layout_width =0dp

The simplest solution is have your list item layout, inflated in your listadapter, simply be a linearlayout with weightSum="3" containing 3 edittexts with layout_weight="1" and layout_width="0dp"

所以你list_item.xml看起来是这样的:

so your list_item.xml would look something like:

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:weightSum="3">
    <EditText android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1" 
        android:visibility="invisible"/>
    <EditText android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1" 
        android:visibility="invisible"/>
    <EditText android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1" 
        android:visibility="invisible"/>
</LinearLayout>

然后,在onclick您的按钮,遍历列表行的孩子和可见性设置为可见。

Then, in the onClick for your button, iterate through the children of the list row and set the visibilities to visible.

对于动态添加行,请使用listadapter和收集,并使用notifydatasetchanged更新列表,当您的收藏收益/损失的物品。

As for adding rows dynamically, use a listadapter and a collection and use the notifydatasetchanged to update the list when your collection gains/loses items.

这篇关于Android的ListView控件:如何添加各种itens连续以动态的方式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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