- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我有这段代码,其中每次前一个 lineaLayout 的编辑文本失去焦点时,我都会膨胀一个包含 3 个 editText 的 linearLayout。我只想在最近创建的 editTexts 上使用 onFocusChangeListener。相反,onFocusChangeListener 仅在第一个 linearLayout 失去焦点时被调用,而其他的则不会。
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.sale_purchase_vouch);
no=0;
for(int i=0;i<30;i++)
flag[i]=true;
save=(Button)findViewById(R.id.Save);
save.setText("Confirm Purchase");
LayoutInflater l=getLayoutInflater();
container=(LinearLayout)findViewById(R.id.container);
row[no]=(LinearLayout)l.inflate(R.layout.row, container);
items[no]=(AutoCompleteTextView)row[no].findViewById(R.id.item);
quants[no]=(EditText)row[no].findViewById(R.id.quant);
rates[no]=(EditText)row[no].findViewById(R.id.rate);
quants[no].setOnFocusChangeListener(this);
flag[no]=false;
}
@Override
public void onFocusChange(View arg0, boolean arg1) {
// TODO Auto-generated method stub
if(flag[no+1]==true){
if(arg1==false){
no++;
LayoutInflater g=getLayoutInflater();
row[no]=(LinearLayout)g.inflate(R.layout.row, container);
items[no]=(AutoCompleteTextView)row[no].findViewById(R.id.item);
quants[no]=(EditText)row[no].findViewById(R.id.quant);
rates[no]=(EditText)row[no].findViewById(R.id.rate);
Log.d("detection", "Row is "+ no+ arg0.getId());
}
}
}
我创建了一个 bool 值数组来了解最后一个 editText 是否创建了一个新的 linearLayout(监听了 onFocusChangeListener)。帮助!!!
最佳答案
您需要扩展 EditText
类,以便创建您自己的 View
类型,其中可能需要一个将实现 View.OnFocusChangeListener 的内部类和 public
方法,因此您可以使用新创建类型的实例使用此内部类的实例设置监听器。
关于android - 如何在动态创建的一组 editText 上设置 onFocusChangeListener()?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18258875/
我只从事 Android 应用程序开发工作几天,所以请原谅我的无知。我正在尝试为 EditText 设置一个监听器,该监听器将在该字段失去焦点后触发。我在 java 中找到了一些示例,但找不到用于 m
我的 Activity 中有一个 EditText。 OnFocusChangeListener 仅在选择另一个 EditText(或输入)时调用。 我如何确定我的 EditText 之外的点击(就像
我正在开发示例应用程序来测试 OnFocusChangeListener,我将调试点放在它的方法上 public void onFocusChange(View v, boolean hasFocus
我在 ListFragment 中有一个 ListView,我想在用户更改列表中的焦点项时更改 fragment 的背景。我特意在这里说焦点,因为这是一个 Google TV 应用程序,所以我针对方向
我为 Android 计算器应用程序编写了一些代码。我想要的是:- 如果 EditText 字段失去焦点,所有输出字段都应该得到更新,就像在 Excel 工作表中发生的那样,如果我们更新单元格中的任何
我有一个标准的文本字段,我想知道用户何时在其中设置焦点。有没有办法做到这一点? 我尝试设置可点击修饰符以在有人单击它时触发事件,但看起来它不适用于 TextField: modifier = Modi
我目前正在尝试为我的应用程序提供一个直观的界面。 我有一个 oncreate 函数可以在加载时激活键盘,效果很好。 public void onCreate(Bundle savedInstanceS
myEdit1.setOnKeyListener(new OnKeyListener() { public boolean onKey(View v, int keyCode,
我正尝试按如下方式自定义 View.onFocusChangeListener 类: private class myCostBoxFocusListener implements View.onFo
我做了一个 EditText OnFocusChangeListener据推测,当它不在焦点上时,它会隐藏光标和另一个 View (即单击屏幕上除 EditText 之外的任何位置将隐藏这些项目)。点
我在用户输入表单上有一个 EditText 行。单击 EditText 以启动 DatePickerDialog 使用 setOnTouchListener 效果很好。我设置的用于处理 EditTex
我在 Activity 中有一个 SearchView;当用户执行搜索时,一个包含搜索结果的 Fragment 被添加到同一个 Activity 中。 现在我想要的是当 SearchView 被点击时
我有这段代码,其中每次前一个 lineaLayout 的编辑文本失去焦点时,我都会膨胀一个包含 3 个 editText 的 linearLayout。我只想在最近创建的 editTexts 上使用
我需要为我的 EditText 实现一次性 OnFocusChangeListener。即,一旦 EditText 获得焦点,它就会执行某些操作并停止监听焦点更改事件。 我将一个任意的 OnFocus
我的 Activity 中有两个 EditText,每个都在 TextInputLayout 中: 此外,在
我正在使用一个包含 EditText 的库,我需要检测此 EditText 何时失去焦点。该库已在此 EditText 上添加了一个 OnFocusChangeListener,因此我无法覆盖此监听器
我想为我拥有的每个 EditText(在我的例子中是 VerifiedEditText)设置自动滚动。我是这样做的,但我认为这不是应该的方式(看起来太复杂、太乱、太长),你能推荐我让它更简单吗?我仍在
我有一个微调器,可以与标准 OnItemSelectedListener 一起正常工作以呈现一组选项: s.setAdapter(adapter); s.setOnItemSelectedListen
没有比标题更清楚的了。我有一个由文本输入布局包裹的 EditText。我试图在 EditText 失去焦点时触发一个事件。但是,一旦应用了事件监听器,TextInputLayout 就不再为文本设置动
我正在尝试在 EditText 上实现 OnFocusChangeListener。问题是我收到此错误 Class 'FacilityScreen' must either be declared a
我是一名优秀的程序员,十分优秀!