我正在布局文件中创建一个包含Activity
[包含ListView
和Button
]的示例应用程序。 ListView
是自定义的,包含[Label / Name和CheckBox]。我想编写一些代码,这些代码将根据列表项Button
检查[T / F],从ListView
的适配器类更改CheckBox
的文本。
答案 0 :(得分:0)
listView.setOnItemClickListener(new OnItemClickListener()
{
public void onItemClick(AdapterView<?> parent, View view, int position, long id)
{
// When clicked, show a toast with the TextView text
AppListOfAllApps Selecteditems = (AppListOfAllApps) parent.getItemAtPosition(position);
if (view != null)
{
CheckBox checkBox = (CheckBox) view.findViewById(R.id.checkBox1);
Selecteditems = (AppListOfAllApps) checkBox.getTag();
//here you will get the selected item you may also get the text from it accordingly and then using using button variable just set text
button.settext("whatever");
}
}
});
答案 1 :(得分:0)
活动:
public class Your_Activity extends Activity implements OnCheckListener// Implement your listener here
@Override
public void OnCheck(int position) {
// TODO Auto-generated method stub
// notify your activity component here
}
在适配器类中:
private OnCheckListener listener;
public interface OnCheckListener {
public void OnCheck(int position);
}
public Your_adapter_constructor(OnCheckListener listener) {
// TODO Auto-generated constructor stub
this.listener = listener;
}
// On your getView()
checkbox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
listener.OnCheck(position);// If you want to pass some value add it here
}
});