Note that there are some explanatory texts on larger screens.

plurals
  1. POGet access to an image view from ListFragment
    text
    copied!<p>I have a ListFragment with its Layout A and for each item on the list I have its layout as well called B. Inside B I have an image view with id "imgVi":</p> <pre><code>&lt;ImageView android:id="@+id/imgVi" android:layout_width="wrap_content" android:layout_height="wrap_content"/&gt; </code></pre> <p>From my ListFragment in the method onCreateView I want to get access to this ImageView for change the image src. How can I do this?. Since this imageView is not in the ListFragment layout, I cant do this:</p> <pre><code>ImageView imgEmp = (ImageView) view.findViewById(R.id.imageViewEmp); imgEmp.setBackgroundResource(R.drawable.ic_tab_emp_selected); </code></pre> <p>But layout B is in layout A. Because its a list with its rows.</p> <p>Any help will be apreciated. I'm new with Android.</p> <p>EDITED: I got it work, just follow this tutorial <a href="http://thinkandroid.wordpress.com/2010/01/11/custom-cursoradapters/" rel="nofollow">http://thinkandroid.wordpress.com/2010/01/11/custom-cursoradapters/</a></p> <pre><code>public class ListClientsCursorAdapter extends SimpleCursorAdapter{ private Context context; private int layout; public ListClientsCursorAdapter(Context context, int layout, Cursor c, String[] from, int[] to, int flags) { super(context, layout, c, from, to, flags); this.context = context; this.layout = layout; } @Override public View newView(Context context, Cursor cursor, ViewGroup parent) { Cursor c = getCursor(); final LayoutInflater inflater = LayoutInflater.from(context); View v = inflater.inflate(layout, parent, false); int nameCol = c.getColumnIndex("name"); String name = c.getString(nombreCol); int telfCol = c.getColumnIndex("telf"); String telf = c.getString(telfCol); /** * Next set the name of the entry. */ TextView name_text = (TextView) v.findViewById(R.id.textViewNombEmp); if (name_text != null) { name_text .setText(name); } TextView telf_text = (TextView) v.findViewById(R.id.textViewTelfEmp); if (telf_text != null) { telf_text.setText(telf); } ImageView imgEmp = (ImageView) v.findViewById(R.id.imageViewEmp); if (imgEmp != null) { imgEmp.setBackgroundResource(R.drawable.ic_tab_emp_selected); } return v; } } </code></pre> <p>And then in my onCreateView of the ListFragment I call:</p> <pre><code>ListClientCursorAdapter notes = new ListClientCursorAdapter(context,R.layout.activity_fil_client, mCursor, from, to, 0); setListAdapter(notes); </code></pre> <p>Instead of SimpleCursorAdapter.</p>
 

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