title: Accessing a Radio Button in a ListView in a Fragment (get updatet from another Fragment)
body: <p>I have got two (List-)Fragments within an Activity. When a line is selected in the left Fragment I display some data in the right Fragment, which is also a ListView. A line of this View contains a TextView and three RadioButtons. </p>
  
  <p>My target is to get these Buttons, f.e. to set values and to set a onClickListener.</p>
  
  <p>My problem is, that my onItemSelected() in the right Fragment didn't work but I don't know why. I try to exend from ListFragment (as the left Fragment) and also a ListView with an custom id.</p>
  
  <ul>
  <li>do I have to extend from ListFragment or is this the same like an normal ListView?</li>
  <li>do I have to use onActivityCreate for setting the onClickListener?</li>
  </ul>
  
  <p>This code is the product of many attempts to try some code from different posts. I see there are some errors.</p>
  
  <p>This is my left Fragment:</p>
  
  <pre><code>public class HeaderListFragment extends ListFragment {
  private final static String TAG = "HeaderListFragment";
  List&lt;ChecklistItem&gt; header;
  static ArrayList&lt;HashMap&lt;String,String&gt;&gt; list = new ArrayList&lt;HashMap&lt;String,String&gt;&gt;();
  
  
  private DBManager db_manager;
  private SimpleAdapter simpleAdapter;
  
  //getstring -&gt; BUG
  String[] from = { "number","text" };
  int[] to = { R.id.listele_header_no, R.id.listele_header_text};
  
  public void buildList(){
      Log.v(TAG, "buildList");
      list = new ArrayList&lt;HashMap&lt;String,String&gt;&gt;();
      for (ChecklistItem item : header){
          HashMap&lt;String, String&gt; map = new HashMap&lt;String, String&gt;();
          map.put("number", item.getnumber());
          map.put("text", item.gettext());        
          list.add(map);
      }
  }
  
  @Override
  public void onListItemClick(ListView l, View v, int position, long id) {
      super.onListItemClick(l, v, position, id);
  
      updateDetail(header.get(position).getparent_id());
  }
  
  @Override
  public void onAttach(Activity activity) {
      // TODO Auto-generated method stub
      super.onAttach(activity);
  }
  
  @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
        Bundle savedInstanceState) {
      View view = inflater.inflate(R.layout.headerfragment,
          container, false);
  
      db_manager = new DBManager(getActivity().getContentResolver());
  
      header = db_manager.getItemHeader();
      Log.v(TAG, "HEADER LIST SIZE "+header.size());
  
  
      buildList();
  
      simpleAdapter = new SimpleAdapter(getActivity(),
              list,
              R.layout.headeritem_row,
              from,
              to);
      setListAdapter(simpleAdapter);
      Log.v(TAG, "set adapter");
  
  
      return view;
    }
  
    // May also be triggered from the Activity
    public void updateDetail(int id) {
  
      QuestionListFragment fragment = (QuestionListFragment) getFragmentManager()
          .findFragmentById(R.id.questionFragment);
      if (fragment != null &amp;&amp; fragment.isInLayout()) {
        fragment.setUI(id);
      } 
  </code></pre>
  
  <p>And my right Fragment:</p>
  
  <pre><code>public class QuestionListFragment extends ListFragment {
  private final static String TAG = "QuestionListFragment";
  
  List&lt;ChecklistItem&gt; questions;
  static ArrayList&lt;HashMap&lt;String,String&gt;&gt; list = new ArrayList&lt;HashMap&lt;String,String&gt;&gt;();
  private DBManager db_manager;
  private SimpleAdapter simpleAdapter;
  private ProgressDialog dialog;
  private RadioGroup radioGroup;
  private RadioButton yes, na, open;
  private ListView listview;
  
  //getstring -&gt; BUG
  String[] from = { "number","text" };
  int[] to = { R.id.listele_question_no, R.id.listele_question_text};
  
  
  public void buildList(){
      Log.v(TAG, "buildList");
      list = new ArrayList&lt;HashMap&lt;String,String&gt;&gt;();
      for (ChecklistItem item : questions){
          Log.v(TAG, item.gettext());
          HashMap&lt;String, String&gt; map = new HashMap&lt;String, String&gt;();
          map.put("number", item.getnumber());
          map.put("text", item.gettext());        
          list.add(map);
      }
  }
  
  @Override
  public void onAttach(Activity activity) {
      // TODO Auto-generated method stub
      super.onAttach(activity);
  }
  
   @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
        Bundle savedInstanceState) {
      View view = inflater.inflate(R.layout.questionfragment,
          container, false);
  
      Log.v(TAG, "onCreateView");
  
  
  
      db_manager = new DBManager(getActivity().getContentResolver());
      return view;
    }
  
  
   @Override
  public void onActivityCreated(Bundle savedInstanceState) {
      super.onActivityCreated(savedInstanceState);
      Log.v(TAG, "onActivityCreated");
      listview = getListView();
      listview.setOnItemClickListener(new OnItemClickListener() {
  
              @Override
              public void onItemClick(AdapterView&lt;?&gt; arg0, View arg1, int position,
                      long arg3) {
  
                  Log.d(TAG, "--&gt; onItemClick listener..."); // You should see this now
  
                  }*/
              }});
  }
  
  
    public void setUI(Integer parent_id) {
        Log.v(TAG, "setUI");
  
  
        questions = db_manager.getQuestions(parent_id);
        buildList();
        simpleAdapter = new SimpleAdapter(getActivity(),
                  list,
                  R.layout.questionitem_row,
                  from,
                  to);
  
          listview.setAdapter(simpleAdapter);
          setListAdapter(simpleAdapter);
          Log.v(TAG, "set adapter");
  </code></pre>
  
  <p>With your feedback it works ! This is my code:</p>
  
  <pre><code>public class QuestionListFragment extends ListFragment {
  private final static String TAG = "QuestionListFragment";
  
  List&lt;ChecklistItem&gt; questions;
  static ArrayList&lt;HashMap&lt;String,String&gt;&gt; list = new ArrayList&lt;HashMap&lt;String,String&gt;&gt;();
  private DBManager db_manager;
  private ProgressDialog dialog;
  private ListViewCustomAdapter adapter;
  
  public void buildList(){
      Log.v(TAG, "buildList");
      list = new ArrayList&lt;HashMap&lt;String,String&gt;&gt;();
      for (ChecklistItem item : questions){
          Log.v(TAG, item.gettext());
          HashMap&lt;String, String&gt; map = new HashMap&lt;String, String&gt;();
          map.put("number", item.getnumber());
          map.put("text", item.gettext());        
          list.add(map);
      }
  }
  
  @Override
  public void onAttach(Activity activity) {
      super.onAttach(activity);
  }
  
   @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
        Bundle savedInstanceState) {
      View view = inflater.inflate(R.layout.questionfragment,
          container, false);
  
      Log.v(TAG, "onCreateView");
  
      db_manager = new DBManager(getActivity().getContentResolver());
  
      return view;
    }
  
  
   @Override
  public void onActivityCreated(Bundle savedInstanceState) {
      super.onActivityCreated(savedInstanceState);
      Log.v(TAG, "onActivityCreated");
  
      getListView().setOnItemClickListener(new OnItemClickListener() {
              @Override
              public void onItemClick(AdapterView&lt;?&gt; arg0, View arg1, int position,
                      long arg3) {
                  Log.d(TAG, "--&gt; onItemClick listener..."); 
              }});
  
  }
  
  
    public void setUI(Integer parent_id) {
        Log.v(TAG, "setUI");
  
        questions = db_manager.getQuestions(parent_id);
        buildList();  
        adapter = new ListViewCustomAdapter(getActivity(), (ArrayList) questions);
        setListAdapter(adapter);
        Log.v(TAG, "set adapter");
  
    }
  
  
    public class ListViewCustomAdapter extends BaseAdapter{
          ArrayList&lt;ChecklistItem&gt; itemList;
          public Activity context;
          public LayoutInflater inflater;
  
          public ListViewCustomAdapter(Activity context, ArrayList&lt;ChecklistItem&gt; itemList) {
              super();
              this.context = context;
              this.itemList = itemList;
              this.inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
          }
  
          @Override
          public int getCount() {
              return itemList.size();
          }
  
          @Override
          public Object getItem(int position) {
              return itemList.get(position);
          }
  
          @Override
          public long getItemId(int position) {
              return 0;
          }
  
          public class ViewHolder
          {
              TextView number;
              TextView text;
              RadioButton yes,na,open;
          }
  
          @Override
          public View getView(int position, View convertView, ViewGroup parent) {
  
              final int pos = position;
  
              ViewHolder holder;
              if(convertView==null)
              {
                  holder = new ViewHolder();
                  convertView = inflater.inflate(R.layout.questionitem_row, null);
  
                  holder.text = (TextView) convertView.findViewById(R.id.listele_question_text);
                  holder.number = (TextView) convertView.findViewById(R.id.listele_question_no);
                  holder.yes = (RadioButton)convertView.findViewById(R.id.rb_yes);
  
                  RadioButton rb = (RadioButton)convertView.findViewById(R.id.rb_yes);
                  rb.setOnClickListener(new View.OnClickListener() {
                      @Override
                      public void onClick(View v) {
                          Log.v(TAG, "yes");
                          Log.v(TAG, questions.get(pos).gettext());
                      }
                  });
  
                  holder.yes = rb;
  
                  convertView.setTag(holder);
              }
              else
                  holder=(ViewHolder)convertView.getTag();
                  ChecklistItem item = (ChecklistItem) itemList.get(position);
                  holder.text.setText(item.gettext());
                  holder.number.setText(item.getnumber());
                  return convertView;
         }
    }
  </code></pre>