Note that there are some explanatory texts on larger screens.

plurals
  1. POthe second listview in the listfragment doesn't scroll
    primarykey
    data
    text
    <p>I created an app in which there are two fragments and in both fragments there are listviews. The first listview in the fragment1 is getting scrolled and the items are also getting highlighted. But in the second fragment, the listview is not scrolled and even the items are not getting highlighted. Can someone tell me what is the problem? The thing here is I just checked this with putting the same fragment class to both fragments in xml. Either they both should work or the both shouldn't because one is no different from the other. But why this problem occurs? </p> <p>My fragment class:</p> <pre><code>public class Fragment1 extends ListFragment{ String[] countries = new String[] { "India", "Pakistan", "Sri Lanka", "China", "Bangladesh", "Nepal", "Afghanistan", "North Korea", "South Korea", "Japan" }; public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { return inflater.inflate(R.layout.fragment1,container,false); } public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); ArrayAdapter&lt;String&gt; adapter=new ArrayAdapter&lt;String&gt;(getActivity(),android.R.layout.simple_list_item_1,countries); setListAdapter(adapter); } public void onListItemClick(ListView parent, View v,int position, long id) { Toast.makeText(getActivity(), "You have selected "+countries[position], Toast.LENGTH_SHORT).show(); } } </code></pre> <p>main.xml:</p> <pre><code>&lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="horizontal" &gt; &lt;fragment android:name="com.example.listfragmentexample.Fragment1" android:id="@+id/fragment1" android:layout_weight="0.5" android:layout_width="0dp" android:layout_height="200dp" /&gt; &lt;fragment android:name="com.example.listfragmentexample.Fragment1" android:id="@+id/fragment2" android:layout_weight="0.5" android:layout_width="0dp" android:layout_height="300dp"/&gt; &lt;/LinearLayout&gt; </code></pre> <p>fragment1.xml:</p> <pre><code>&lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" &gt; &lt;ListView android:id="@id/android:list" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_weight="1" android:drawSelectorOnTop="false"/&gt; &lt;/LinearLayout&gt; </code></pre>
    singulars
    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