Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to pass a value from anadapter class to activity
    primarykey
    data
    text
    <p>i want to pass the value of the list(itemvalue) from the adapter class to a activity.Since i am extending the arrayadapter class and not the Activity, i cannot use sharedpreference.I am taking this values into the arraylist(itemname) inside a listener.Here is the code that i have tried.Can anyone help me to solve this....</p> <pre><code>public class CustomArrayAdapter extends ArrayAdapter&lt;Model&gt; { protected static final String MODE_PRIVATE = null; private final List&lt;Model&gt; list; private final Activity context; public CustomArrayAdapter(Activity context, List&lt;Model&gt; list) { super(context, R.layout.customlistlayout, list); this.context = context; this.list = list; } static class ViewHolder { protected TextView mText; protected CheckBox mCheckbox; public string getItemAtPosition(int i) { // TODO Auto-generated method stub return null; } } @Override public View getView(int position, View convertView, ViewGroup parent) { View view = null; if (convertView == null) { final ArrayList&lt;String&gt; itemname = new ArrayList&lt;String&gt;(); LayoutInflater inflator = context.getLayoutInflater(); view = inflator.inflate(R.layout.customlistlayout, null); final ViewHolder viewHolder = new ViewHolder(); viewHolder.mText = (TextView) view.findViewById(R.id.settings_label); viewHolder.mCheckbox = (CheckBox) view.findViewById(R.id.check); Activity activity = new SettingsActivity(); viewHolder.mCheckbox.setOnCheckedChangeListener(activity); viewHolder.mCheckbox .setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { Model element = (Model) viewHolder.mCheckbox .getTag(); element.setSelected(buttonView.isChecked()); **itemname.add(element.getName());** } }); for (String myValue : itemname) { System.out.println(myValue); } view.setTag(viewHolder); viewHolder.mCheckbox.setTag(list.get(position)); } else { view = convertView; ((ViewHolder) view.getTag()).mCheckbox.setTag(list.get(position)); } ViewHolder holder = (ViewHolder) view.getTag(); holder.mText.setText(list.get(position).getName()); holder.mCheckbox.setChecked(list.get(position).isSelected()); return view; } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload