- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
这是一个库存盘点应用程序...加载库存数据库中的项目数量,库存审计员必须输入每个项目的盘点数量,应用程序会告诉他们它是否正确。:
< br/>1) 应用程序从服务器接收一个包含商品列表及其库存数量的 JSON 字符串。它被加载到名为“jArray”的数组中
2) 从此数组中,UI 在新行中显示每个项目:
第 1 列:项目描述,
第 2 列:用于用户输入盘点数量的编辑文本字段,
第 3 列:包含正确数量的隐藏(白色背景中的白色文本)字段..
< br/>3) 如果输入的数量与 col 3 中的文本不匹配,那么它会将 col3 textview 颜色更改为红色作为警告...
问题是,我如何在同一表格行上引用/检查以编程方式创建的相邻 TextView 的值,并更改其文本颜色?
在带有 javascript 的 html 网站上,这只是引用同一父节点下的第 3 列子节点的问题……但是在 android/java 中有什么等价物……或者有更简单的方法吗?
谢谢
for (int i=0; i < jArray.length(); i++)
{
try {
JSONObject oneObject = jArray.getJSONObject(i);
// Pulling items from the array
item = oneObject.getString("item");
qty = oneObject.getString("qty");
// textview on column 1 containing item descr
TableRow tbrow = new TableRow(this);
TextView t1v = new TextView(this);
t1v.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.WRAP_CONTENT, TableRow.LayoutParams.WRAP_CONTENT, 0.1f));
t1v.setText(item);
tbrow.addView(t1v);
// Add edit text field for qty input
EditText t4v = new EditText(this);
t4v.setInputType(InputType.TYPE_CLASS_NUMBER);
t4v.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.WRAP_CONTENT, TableRow.LayoutParams.WRAP_CONTENT, 0.1f));
tbrow.addView(t4v);
t4v.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence https://stackoverflow.com/editing-helpcharSequence, int i, int i1, int i2) {
}
@Override
public void onTextChanged(CharSequence s, int start,
int before, int count) {
// after input from android keypad, check whether the number matches with qty in adjacent textview, if not matching, change adjacent textview color to red
if(s != ***value in adjacent textview *****) {
t5v.setTextColor(Color.RED);}
}
@Override
public void afterTextChanged(Editable editable) {
}
});
// Add invisible textview (text in white) holding actual quantity of item
TextView t5v = new TextView(this);
t5v.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.WRAP_CONTENT, TableRow.LayoutParams.WRAP_CONTENT, 0.1f));
t5v.setText(qty);
t5v.setTextColor(Color.WHITE);
最佳答案
当使用 View.setTag(Object)
将其添加到表格行时,您可以在 TextView
上设置标签。例如使用一些
private static final String QUANTITY_VIEW = "quantity";
写
t5v.setTag(QUANTITY_TAG);
tbrow.add(t5v);
然后你可以通过写来检索它
TextView textView = (TextView) tbrow.findViewWithTag(QUANTITY_TAG);
另请参阅 View.findViewWithTag() 的文档
关于java - 安卓工作室 : How to programmatically change an adjacent TextView on the same tablerow?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52083735/
我的问题分为两部分 1) 我想将文件名分配给 FileUpload 控件然后保存它,但问题是它是只读的 FileUpload1.FileName="ClientMachine\\Ima
我目前正在开发一个适用于 iOS 和 macOS 的跨平台应用程序,使您的 iOS 设备可以用作触控板。 使用CGDisplayMoveCursorToPoint,我可以在屏幕上移动光标。奇迹般有效。
要为其他应用程序提供 API,我们可以使用 android:exported="true" 导出我们自己的内容提供程序、服务和广播接收器在我们的应用程序中的 AndroidManifest.xml .
我正在构建一个同义词库应用程序,对于这个问题,关键是我正在为特定单词(例如 - “feline”、“tomcat”)添加同义词列表(具有相同含义的单词) "、"puss"是 "cat"的同义词) 我有
我正在创建音频,为它分配源并使用jquery以编程方式将其附加到页面,我还需要向该音频添加一个类,但是我无法使其工作,我尝试了以下操作: var song = new Audio(); song.sr
我想以编程方式使用 RadioButton 的属性 - android:button="@drawable/abc"。 我如何用 Java 编写这个? 最佳答案 试试这个 radioButton.se
什么是 QTP 中的描述性编程? 最佳答案 在不使用对象存储库的情况下创建测试称为描述性编程,因为您将对象描述为脚本的一部分。 例如 Browser("title:=Google").Page("ti
这个问题在这里已经有了答案: Android Activity, how to override manifest's android:configChanges with Java code? (2
我正在尝试将二进制数据存储在动态创建的 JCR 中。我的问题是 JCR API 提供的唯一方法是通过 InputStream : Session session = request.getResour
这个问题在这里已经有了答案: Set EditText Digits Programmatically (6 个回答) 2年前关闭。 我目前正在使用 android:digits="qwertzuio
我正在开发 Windows 窗体应用程序。我有以下问题:在一个表单中有一个面板,在那个面板中我有许多控件(只是一个带有文本框的标签,数量是在运行时确定的)。此面板的大小小于动态添加的所有控件的总和。所
在国际象棋小程序的框架内,我有几套这样的灰度/黑白(不确定): 有什么方法可以通过 Java 代码为 PNG 图片赋予色调?尝试用谷歌搜索此事,但没有找到任何真正符合我正在寻找的东西。 例如,对于下面
我有一个 CompilationUnit,其中包含一个未导入对另一个类的引用的类。Eclipse 轻松解决了此类问题,并建议导入缺少的类(位于父包中)。 如何在不知道其名称或位置的情况下以编程方式导入
我可以完全访问 Android 系统。我拥有所有 super 用户权限,可以从我的任何应用程序中执行所有操作。我只想实现一项功能,其中我需要重置设备而不将用户重定向到 PRIVACY_SETTINGS
Android Q 引入了一项设置,可以在应用程序上强制使用深色模式,而无需担心手动更改颜色:https://developer.android.com/preview/features/darkth
好的,所以我做了一些研究,似乎一致认为您不能以编程方式更新 android:updatePeriodMillis。 看来您必须改用 AlarmManager,这就像使用大锤来敲开坚果一样……奇怪的是
我正在努力在我的表格 View 中实现一些自定义操作。目前我在下面的代码中创建了一个自定义操作。 override func tableView(tableView: UITableView, edi
我有这个委托(delegate),它打算在用户用手指滚动时执行: -(void)scrollViewDidScroll:(UIScrollView *)scrollView 我有一行代码滚动到开头:
如果我们有这段代码: int a; cout > a; 在终端中,输入请求看起来像这样 please enter a value: _ 我如何以编程方式模拟用户在其中的输入。 最佳答案 下面是一个示例
是否可以通过 java 方法以编程方式重新呈现 a4j:outputPanel? 最佳答案 您可以保留民意调查,并在方法中设置一些标志(如果该标志已在民意调查中捕获),因为设置只是渲染面板 关于jav
我是一名优秀的程序员,十分优秀!