android 表格内的可聚焦行

2024-05-05

我在 xml 中有一个 ScrollView,其中包括一个 TableLayout。 我的问题是,每次我单击它时是否可以有一个可聚焦的行。 这是我的 xml 代码:

    <ScrollView 
        android:orientation="vertical"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content">

        <TableLayout 
            android:id="@+id/table2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" >
            <TableRow>
                <RelativeLayout
                    android:id="@+id/rowlayout"
                    android:layout_width="wrap_content"
                    android:layout_height="fill_parent"
                    android:background="@drawable/rowbackground2" >
                        <ImageView
                            android:id="@+id/icon"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:src="@drawable/icon_code_contact" 
                            android:padding="7dip"
                            android:layout_alignParentLeft="true" />

                        <TextView
                            android:id="@+id/contacts"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:textStyle="bold"
                            android:text="Contacts"
                            android:textColor="#000"
                            android:textSize="18dip"
                            android:layout_toRightOf="@id/icon"
                            android:paddingTop="10dip" />

                </RelativeLayout>
            </TableRow>


            <TableRow>
                <Button
                    android:id="@+id/contacts_button"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:background="@drawable/contact_button" />
            </TableRow>

我已经尝试过“focusable =“true””和“focusableInTouchMode =“true””但什么也没发生..

提前致谢


如果您询问如何使表格表现得像 ListView,我做了以下操作:

在定义 Activity 布局的 xml 文件中,我定义了该表:

<ScrollView
    android:layout_height="wrap_content"
    android:layout_width="fill_parent" >
    <TableLayout
        android:id="@+id/my_table"
        android:layout_height="fill_parent"
        android:layout_width="fill_parent"
        android:stretchColumns="1"
        android:shrinkColumns="1"/>
</ScrollView>

然后我就单独写了table_row_item.xml具有表行布局的文件:

<?xml version="1.0" encoding="UTF-8"?>
<TableRow xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="?android:attr/listPreferredItemHeight"
    android:focusable="true"
    android:focusableInTouchMode="false"
    android:clickable="true"
    android:background="@android:drawable/list_selector_background">

    <TextView
        android:id="@+id/cell_1"
        ...
    />
    ...
    <TextView
        android:id="@+id/cell_N"
        ...
    />
</TableRow>

在活动中,我声明了向表中添加一行的过程:

private void addTableRow() {
    final TableLayout table = (TableLayout) findViewById(R.id.my_table);
    final TableRow tr = (TableRow) getLayoutInflater().inflate(R.layout.table_row_item, null);

    TextView tv;
    // Fill out our cells
    tv = (TextView) tr.findViewById(R.id.cell_1);
    tv.setText(...);
    ...
    tv = (TextView) tr.findViewById(R.id.cell_N);
    tv.setText(...);
    table.addView(tr);

    // Draw separator
    tv = new TextView(this);
    tv.setBackgroundColor(Color.parseColor("#80808080"));
    tv.setHeight(/*height of separaor line. 2dip will be enough*/);
    table.addView(tv);

    // If you use context menu it should be registered for each table row
    registerForContextMenu(tr);
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

android 表格内的可聚焦行 的相关文章

  • 如何在android网络库(ION)中使用自签名SSL?

    使用此网络库 https github com koush ion https github com koush ion 由于当前状态是开发 我想使用自签名 SSL 证书 图书馆论坛有一些讨论 https github com koush
  • 如何在 ADB 连接期间禁用电池充电?

    问题描述 每次我在电脑和手机之间连接 USB 线时 电池都会自动充电 我想使用 ADB 协议 但我不想在 ADB 连接期间为电池充电 是否可以关闭此充电功能 当然 我该怎么做呢 环境 Android 操作系统 4 及更高版本的手机 我只需要
  • 如何在 android 中启动“添加联系人”活动

    您能告诉我如何在 Android 中启动 添加联系人 活动吗 谢谢 API 级别 5 及以上解决方案 Add listener so your activity gets called back upon completion of act
  • Android 中的 Sugar ORM:更新 SQLite 中保存的对象

    我是在 Android 上使用 SQLite 和 Sugar ORM 进行应用程序开发的新手 并尝试阅读 Sugar ORM 文档 但没有找到有关如何更新 SQLite 中保存的对象的任何信息 更改对象属性后还可以保存对象吗 就像是 Cus
  • API29 上不推荐使用 setColorFilter

    我使用以下行来更改 VectorDrawable 的颜色 mydrawable getBackground setColorFilter color PorterDuff Mode SRC ATOP 这很好用 尽管它现在已被弃用 文档建议我
  • 如何在活动中的必填字段中显示 * 符号

    我需要在活动中的必填字段中显示 符号 你能建议我怎样才能做到这一点吗 任何帮助 将不胜感激 我想说 作为必填字段的标记不遵循本机 Android 主题 的组合setHint and setError对于 Android 应用程序来说看起来更
  • Android:如何使用后台线程?

    我开发了一个应用程序 它从互联网获取内容并相应地在设备的屏幕上显示它 该程序运行得很好 就是有点慢 加载并显示内容大约需要 3 4 秒 我想将获取内容并将其显示在后台线程中的所有代码放在一起 当程序执行这些功能时 我想显示一个进度对话框 你
  • Android Fragment onCreateView 与手势

    我正在尝试在片段中使用手势 我在 FragmentActivity 中有以下内容来处理我的详细信息片段 我试图发生的情况是 当在视图上检测到滑动时 将该视图内的数据替换为上一个或下一个条目 如果有更好的方法来处理这个问题 我完全同意 然而
  • Android:使 Dialog 周围的所有内容都比默认值更暗

    我有一个具有以下样式的自定义对话框 它显示了一个无边框对话框 后面的任何内容都会 稍微 变暗 我的设计师希望背后的一切都比 Android 的默认设置更暗 但不是完全黑色 有这样的设置吗 我能想到的唯一解决方法是使用全屏活动而不是对话框 只
  • Emma 不生成coverage.ec

    我设置了艾玛 它曾经对我有用 然后我们更改了源代码 现在它没有生成coverage ec根本不 它确实生成coverage em 测试临近结束时 出现错误消息 exec INSTRUMENTATION CODE 0 echo Downloa
  • 如何从android中的外部存储中获取所选文件的文件路径?

    我在选择文件的文件路径时遇到问题 我搜索了整个堆栈溢出 但问题没有解决 从设备中选择文件的代码如下所示 Intent intent new Intent Intent ACTION GET CONTENT intent setType in
  • 如何使用应用程序接口将蓝牙套接字传递给另一个活动

    因此 根据我收集的信息 套接字连接既不可序列化 也不可分割 但我需要将蓝牙连接传递给另一个活动 我不想作为中间人编写服务 所以请不要将此作为解决方案发布 我听说有一种方法可以使用自定义应用程序接口来传递这些类型的对象 但我一生都找不到这样的
  • Android 时钟滴答数 [赫兹]

    关于 proc pid stat 中应用程序的总 CPU 使用率 https stackoverflow com questions 16726779 total cpu usage of an application from proc
  • Android 地理围栏无法正常工作(未调用 IntentService)

    这是我的代码 安卓清单
  • Android Gradle 同步失败:无法解析配置“:classpath”的所有工件

    错误如下 Caused by org gradle api internal artifacts ivyservice DefaultLenientConfiguration ArtifactResolveException Could n
  • 如何关闭 EditText 中的建议?

    如何在 Android 中关闭 EditText 中的建议 android inputType textNoSuggestions 根据this http comments gmane org gmane comp handhelds an
  • 如何在Android中创建一个简洁的两栏输入表单?

    我想创建一个整洁的两列输入表单 如下所示 到目前为止我的 xml 布局代码
  • 使用 DataBindingComponent 的 Inflate 方法

    当 Glide 成功渲染图像后 我在更新文本视图时看到此错误 致命异常 java lang IllegalStateException 必需 CustomBinding 类中的 DataBindingComponent 为 null 绑定适
  • 使用Intent拨打电话需要权限吗?

    在我的一个应用程序中 我使用以下代码来拨打电话 Intent intent new Intent Intent ACTION CALL Uri parse startActivity intent 文档说我确实需要以下清单许可才能这样做
  • 如何在布局编辑器中模拟沉浸式模式

    我想在布局编辑器中全屏查看我的布局 我正在使用 eclipse 插件 我已经通过选择隐藏了 ActionBar NoActionBar组合中的主题 但导航栏是一个不同的故事 AFAIK 它只能使用代码中的标志来隐藏 我需要在活动 xml 文

随机推荐