Android 表格行 onClick

发布于 2024-12-18 01:57:14 字数 321 浏览 2 评论 0原文

我有一些事情我似乎无法理解,希望得到一些意见。

我有一个非常简单的项目管理器 Android 应用程序,其中有 1 个活动,我在其中动态创建嵌套表布局的表行,以通过游标(SQLite 查询)显示所有项目。

我对 Android 开发还是很陌生,所以任何输入和示例都将受到高度赞赏。

以下是我需要输入的两件事(截至目前): 1)我想更改用户选择的行的背景颜色,以便它脱颖而出...... 2)捕获选择后,我想从选定的表行中提取信息...

旁注:我尝试在这里发布一些代码snipit,但该网站不允许我通过一些空间限制。

谢谢帕拉格

I have a few things that I can't seem to get my head around, and would like to get some input.

I have a very simple item manager Android application, in which I have 1 activity, where I'm dynamically creating table rows for a nested table layout to display all the items by means of a cursor (SQLite query).

I'm very new to android development still, so any input followed by a example will be highly appreciated.

Here are the 2 things (as of now) that i need some input on:
1) i want to change the background color of the row user selects just so that it stands out...
2) after the selection has been captured, i wanted to extract the information from the selected table row...

Side note: I tried to post some code snipit here, but this website wouldn't let me past some space restriction.

Thanks

Parag

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

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

发布评论

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

评论(2

喵星人汪星人 2024-12-25 01:57:14

首先,您是否考虑过使用 ListView 代替? hello-listview
(有像适配器这样的工具可以自动将数据插入列表视图)

每个视图都有可以从一开始就通过布局 XML 设置的属性,并且可以通过视图属性和状态访问和更改这些属性,以便可以更改其颜色 myRow .setBackgroundColor() 并获取属性状态,如当前文本 myTextView.getText()
对于每个视图,您都可以附加一个侦听器 - 例如 onClickListener。

通常这里的人不会回答非常基本的问题,所以我建议你从教程/书籍开始
我真的不想显得居高临下(我自己也很菜鸟)。
就是这样。

希望我能帮忙

firstly , have you considered using a ListView instead? hello-listview
(there's tools like adapters to insert data automatically into listviews)

every View has properties you can set from the get go through the Layout XML and which you can access and change through the View properties and states so you can change its color myRow.setBackgroundColor() and get a property state like current text myTextView.getText() .
and for every view you can attach a listener - for example an onClickListener.

usually people here wont answer very basic question so I advise you start with tutorials/books
I really dont mean to sound patronizing (i'm pretty noob myself).
thats just the case.

hope i could help

深海蓝天 2024-12-25 01:57:14

如果您只想根据项目状态(按下、聚焦、选择等)更改颜色或可绘制对象,最简单的方法可能是使用选择器: http://developer.android.com/guide/topics/resources/color-list-resource.html

来自上面链接的示例:

在 /res/colors/button_text.xml 中:

<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_pressed="true"
          android:color="#ffff0000"/> <!-- pressed -->
    <item android:state_focused="true"
          android:color="#ff0000ff"/> <!-- focused -->
    <item android:color="#ff000000"/> <!-- default -->
</selector>

在您的布局中:

<Button
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="@string/button_text"
    android:textColor="@color/button_text" />

If you just want to change colors or drawables depending on item state (pressed, focused, selected, etc.) the easiest way is probably the use of selectors: http://developer.android.com/guide/topics/resources/color-list-resource.html.

Exmaple from the above link:

in /res/colors/button_text.xml:

<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_pressed="true"
          android:color="#ffff0000"/> <!-- pressed -->
    <item android:state_focused="true"
          android:color="#ff0000ff"/> <!-- focused -->
    <item android:color="#ff000000"/> <!-- default -->
</selector>

in your layout:

<Button
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="@string/button_text"
    android:textColor="@color/button_text" />
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文