gpt4 book ai didi

android - 我如何从android中的复选框获取值

转载 作者:塔克拉玛干 更新时间:2023-11-02 18:53:30 24 4
gpt4 key购买 nike

我想获取在复选框中选中的项目的名称。但我只得到一些字母数字。我如何从复选框中获取所选项目的名称

public View getView(int position, View convertView, ViewGroup parent) {
View view = null;
if (convertView == null) {
LayoutInflater inflator = context.getLayoutInflater();
view = inflator.inflate(R.layout.customlistlayout, null);
final ViewHolder viewHolder = new ViewHolder();
viewHolder.text = (TextView) view.findViewById(R.id.label);
viewHolder.checkbox = (CheckBox) view.findViewById(R.id.check);
viewHolder.checkbox
.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

@Override
public void onCheckedChanged(CompoundButton buttonView,
boolean isChecked) {
Model element = (Model) viewHolder.checkbox
.getTag();

element.setSelected(buttonView.isChecked());


enter code here

//System.out.println(itemname);
}
});
view.setTag(viewHolder);
viewHolder.checkbox.setTag(list.get(position));
} else {
view = convertView;
((ViewHolder) view.getTag()).checkbox.setTag(list.get(position));
}
ViewHolder holder = (ViewHolder) view.getTag();
holder.text.setText(list.get(position).getName());
holder.checkbox.setChecked(list.get(position).isSelected());
return view;
}

最佳答案

我有这样的东西:

CheckBox not = (CheckBox)findViewById(R.id.checkBox1);
not.setChecked(my.notifications);
not.setOnClickListener(new OnClickListener()
{

@Override
public void onClick(View v)
{
if (((CheckBox) v).isChecked())
{


}
else
{

}
}
});

关于android - 我如何从android中的复选框获取值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9990676/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com