当前位置: 动力学知识库 > 问答 > 编程问答 >

How to change list items size by using checkbox with Android?

问题描述:

Can anyone show me how to use checkbox to change items size in listview in Android?

When the checkbox is unchecked ,the items in listview is normal size.

When the checkbox is checked, all items in the listview will enlarged.

code or tips will help ,thanks

网友答案:

This is for checking and setting listview item size in getview of adapter according to checkbox state.

if(!isChecked)
{
   convertView.setLayoutParams(new ListView.LayoutParams(NormalWidth,  
    Normalheight));
}
else
{
 convertView.setLayoutParams(new ListView.LayoutParams(EnlargeWidth,  
    Enlargeheight));
}

and for checkbox checked change you may write like as below:

mCheckBox.setOnCheckedChangeListener(new OnCheckedChangeListener() 
{

@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked)
{
    this.isChecked = isChecked;
    adapter.notifyDataSetChanged();   /* this line will Refress the listview so you can change the value of isChecked variable then it will change the size of listview item.*/
}
}); 
分享给朋友:
您可能感兴趣的文章:
随机阅读: