I have a ListView
with a CustomArrayAdapter
with checkbox
, inside the Onclick
del checkbox
in which CustomArrayAdapter
I want to modify the text of a TextView
del Fragment
, I have tried this but I can't, it doesn't modify the text in the 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();
}
}
My Holder :
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;
}
}
The TextView is declared in the Fragment , it is a normal 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