2015-05-16 74 views
-3

我有1-Checkbox,1-EditText和2-TextView的列表视图。我想要做的是当我点击checkBox然后根据检查状态EditText样式也应该改变。我已经在Baseadapter getView()方法编码如下:Android:以编程方式更改ListView中EditText的样式

我做错了什么?

holder.checkBox.setTag(holder.editText); 
    if (boolAdpaterArrayList.get(position)) { 
        holder.editText.setTextAppearance(context, 
          R.style.edittextStyleChecked); 
        holder.checkBox.setChecked(true); 
       } else { 
        holder.editText.setTextAppearance(context, 
          R.style.edittextStyleUnchecked); 
        holder.checkBox.setChecked(false); 
       } 
     } 

holder.checkBox 
       .setOnCheckedChangeListener(new OnCheckedChangeListener() { 

        @Override 
        public void onCheckedChanged(CompoundButton view, 
          boolean isChecked) { 
        EditText editText = (EditText)buttonView.getTag(); 
        if(isChecked){ 
         editText.setTextAppearance(context, 
            R.style.edittextStyleChecked); 
        }else{ 
         editText.setTextAppearance(context, 
            R.style.edittextStyleUnchecked); 
       } 
       notifyDataSetChanged(); 
        } 
       }); 
+0

为什么downvote ??? – Pankaj

+0

你点击复选框项目后再次刷新列表视图适配器吗? –

+0

是的,我通过notifyDataSetChanged() – Pankaj

回答

0

使用check box state changed listener。如果您使用ViewHolder模式,那么您可以轻松地从参数中提取viewHolder。 它应该看起来像这样

public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { 
ViewHolder holder = (ViewHolder) buttonView.getTag(); 
if (isChecked) { 
      holder.editText.setTextAppearance(context, 
        R.style.edittextStyleChecked); 
     } else { 
      holder.totalRoom.setTextAppearance(context, 
        R.style.edittextStyleUnchecked); 
     } 
} 
} 
+0

无法正常工作。用notifydataSetchanged也检查 – Pankaj

+0

嗯,我只是注意到你使用两个不同的持有人项目进行检查和未检查(editText和totalRoom)。在这两种情况下尝试使用editText或totalRoom。 – torque203

+0

我编辑了这个问题,它也没有什么不同 – Pankaj

相关问题