作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
嘿,我怎么知道单击时下面的复选框来自列表的哪一行。有什么方法可以知道这一点吗?每次 yo 都会返回 false,这是它的默认值。
checkBox.setOnClickListener( new View.OnClickListener() {
public void onClick(View v) {
CheckBox cb = (CheckBox) v ;
callBlockOptions callBlockOptions = (callBlockOptions) cb.getTag();
callBlockOptions.setChecked( cb.isChecked() );
String yo;
if(callBlockOptions.getPosition()=="0")
{
callBlockOptions.setAllCalls();
}
if(callBlockOptions.getAllCalls() ==true)
yo="true";
else
yo="false";
Toast.makeText(getContext(), callBlockOptions.getPosition(), Toast.LENGTH_LONG).show();
}
});
}
最佳答案
查看代码后,您可能想要尝试的一件事是为 ListView 中的各个子项设置监听器。你可以这样做:
ListView listView = (ListView)findViewById(R.id.listView);
int count = listView.getChildCount();
for (int x = 0; x < count; x++)
{
Class<? extends View> c = listView.getChildAt(x).getClass();
if (c == CheckBox.class)
{
CheckBox checkBox = (CheckBox)(listView.getChildAt(x));
checkBox.setOnCheckedChangeListener(new OnCheckedChangeListener(){
@Override
public void onCheckedChanged(CompoundButton compoutButton, boolean isChecked) {
// TODO Auto-generated method stub
callBlockOptions.isChecked = isChecked;
}
});
}
else if (c == TextView.class)
{
TextView textView = (TextView)(listView.getChildAt(x));
textView.setOnEditorActionListener(new OnEditorActionListener(){
@Override
public boolean onEditorAction(TextView tView, int arg1, KeyEvent arg2) {
// TODO Auto-generated method stub
callBlockOptions.name = tView.getText().toString();
return true;
}
});
}
你可能希望你的其他类(class)是这样的:
public class callBlockOptions {
public static String name;
public static Boolean isChecked;
}
然后你可以像这样获取和设置 name 和 isChecked :
callBlockOptions.isChecked = false;
Boolean boolVal = callBlockOptions.isChecked;
关于java - 如何知道 ListView 特定行的复选框值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25333385/
我是一名优秀的程序员,十分优秀!