我有一个ListView
with CustomArrayAdapter
,checkbox
在Onclick
del里面我想修改delcheckbox
的文本,我试过这个但我不能,它不会修改中的文本:CustomArrayAdapter
TextView
Fragment
Fragment
public class CustomArrayAdapter extends ArrayAdapter<Row> implements View.OnClickListener{
private LayoutInflater layoutInflater;
TextView crec;
private Context mcontext;
public CustomArrayAdapter(Context context, List < Row > objects)
{
super(context, 0, objects);
layoutInflater = LayoutInflater.from(context);
this.mcontext = context;
}
@Override
public View getView ( int position, View convertView, ViewGroup parent)
{
// holder pattern
Holder holder = null;
if (convertView == null) {
holder = new Holder();
convertView = layoutInflater.inflate(R.layout.listadapter_multiple, null);
View convertView2 = layoutInflater.inflate(R.layout.fragment_recomendacion, null);
holder.setTextViewTitle((TextView) convertView.findViewById(R.id.textViewTitle));
holder.setTextViewSubtitle((TextView) convertView.findViewById(R.id.textViewSubtitle));
holder.setCheckBox((CheckBox) convertView
.findViewById(R.id.checkBox));
holder.helloTxt= (TextView) convertView2.findViewById(R.id.crec);
convertView.setTag(holder);
} else {
holder = (Holder) convertView.getTag();
}
final Row row = getItem(position);
holder.getTextViewTitle().setText(row.getTitle());
holder.getTextViewSubtitle().setText(row.getSubtitle());
holder.getCheckBox().setTag(position);
holder.getCheckBox().setChecked(row.isChecked());
holder.getCheckBox().setOnClickListener(this);
return convertView;
}
@Override
public void onClick(View v) {
Holder holder = new Holder();
CheckBox checkBox = (CheckBox) v;
int position = (Integer) v.getTag();
final Row row = getItem(position);
if(checkBox.isChecked()) {
holder.helloTxt.setText("eltexto");
notifyDataSetChanged();
}
}
我的持有人:
static class Holder{
TextView textViewTitle;
TextView textViewSubtitle;
CheckBox checkBox;
public TextView helloTxt;
public TextView getTextViewTitle()
{
return textViewTitle;
}
public void setTextViewTitle(TextView textViewTitle)
{
this.textViewTitle = textViewTitle;
}
public TextView getTextViewSubtitle()
{
return textViewSubtitle;
}
public void setTextViewSubtitle(TextView textViewSubtitle)
{
this.textViewSubtitle = textViewSubtitle;
}
public CheckBox getCheckBox()
{
return checkBox;
}
public void setCheckBox(CheckBox checkBox)
{
this.checkBox = checkBox;
}
}
TextView 在 Fragment 中声明,它是一个普通的 TextView:
public class Recomendacion extends Fragment {
...
TextView crec;
//codigo
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
...
crec = (TextView) view.findViewById(R.id.crec);
//codigo
我通过调用
Activity
容器中的函数来解决它Fragment
:在
Activity
其中我创建了修改的函数TextView
:一个建议是添加一个公共方法,您可以在其中更改所需的文本
TextView
,这在类中Recomendacion
:onClick()
在Adapter的方法中CustomArrayAdapter
发送文本:有了这个,您将能够更改文本和您
TextView
的Fragment
Recomendacion
.