Note that there are some explanatory texts on larger screens.

plurals
  1. POViewpager + Listview + setOnItemClickListener and fragment replace
    text
    copied!<p>I browsed StackOverflow for days before deciding to post my own question. I really can't figure this out.</p> <p>I'm using ActionBarSherlock to implement a viewpager with 2 tabs. I managed to get a ListView on the first tab and everything is working perfectly, at least until I click on one of the list items.</p> <p>Here's the interesting code in my SherlockListFragment</p> <pre><code>@Override public void onViewCreated(View view, Bundle savedInstanceState){ // Click event for single list row getListView().setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView&lt;?&gt; parent, View view, int position, long id) { Toast.makeText(getActivity(), "CLICKED", Toast.LENGTH_SHORT).show(); HashMap&lt;String, String&gt; videoz = new HashMap&lt;String, String&gt;(); videoz = (HashMap&lt;String, String&gt;) parent.getAdapter().getItem(position); String videoid = "test"; Prova singleitem = new Prova(); Bundle bundle = new Bundle(); bundle.putString("KEY_ID", videoid); singleitem.setArguments(bundle); FragmentTransaction trans = getFragmentManager().beginTransaction(); trans.replace(R.id.main_layout, singleitem); trans.addToBackStack(null); trans.commit(); } }); } </code></pre> <p>This code actually works and open up my "Prova" fragment, but it breaks everything. It appears below my admob (which is normally sticked to the bottom) and the tab bar doesn't work anymore. What am I missing here?</p> <p>Listview with tab bar still working: <a href="http://imgur.com/FapadTH,TByd05U#1" rel="nofollow">http://imgur.com/FapadTH,TByd05U#1</a> After clicking an item: <a href="http://imgur.com/FapadTH,TByd05U#0" rel="nofollow">http://imgur.com/FapadTH,TByd05U#0</a></p> <p>My main layout</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads" android:layout_width="fill_parent" android:layout_height="fill_parent" android:id="@+id/main_layout" android:orientation="vertical" &gt; &lt;android.support.v4.view.ViewPager xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/pager" android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="1"&gt; &lt;/android.support.v4.view.ViewPager&gt; &lt;LinearLayout android:id="@+id/frame_layout" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_alignParentBottom="true"&gt; &lt;com.google.ads.AdView android:id="@+id/adView" android:layout_width="wrap_content" android:layout_height="wrap_content" ads:adUnitId="xxxxxx" ads:adSize="SMART_BANNER" ads:loadAdOnCreate="false" /&gt; &lt;/LinearLayout&gt; &lt;/LinearLayout&gt; </code></pre> <p>THANKS IN ADVANCE!</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