title: ListView (placed under fragment activity and shown via a ViewPager) doesn't show all items
body: <p>this is the first time posting here. So I have a screenwriting app I am creating using Java on Android. It has a simple layout as shown below.<a href="https://i.stack.imgur.com/mtZ4B.jpg" rel="nofollow noreferrer">layout of the activity</a></p>
  <p>So, when user clicks write, they will be able to write their screenplay using plain text, but following a specific syntax called Fountain. An example is given below.</p>
  <p>If user writes the following text...</p>
  <p>WRITER
  (Smiles)
  I have to do this.</p>
  <p>The app will split the text into lines, and add the different lines to list string (listy), and from there, when the user clicks on the read tab, the app will start from position 0 of listy and check if the item is a scene heading, action, or dialogue, and it will format the text based on that. Action and scene heading gravity is &quot;left&quot;, while dialogue gravity is &quot;center&quot;.</p>
  <p>Everything works fine, I don't get any errors. However, there is only one problem.</p>
  <p>When the user clicks on read, the app shows the script as shown below.</p>
  <p><a href="https://i.stack.imgur.com/emp7l.jpg" rel="nofollow noreferrer">This is what the user writes.</a></p>
  <p><a href="https://i.stack.imgur.com/TLqCf.jpg" rel="nofollow noreferrer">This is what the user sees after formatting the screenplay.</a></p>
  <p>Problems is that after formatting, the listview does not show all items. Like I mentioned above, I split the plain text into individual lines, and add them to ListString(listy), and then after determining whether or not an item from ListString(listy) is an action, or dialogue, or scene heading, I create a map with the keys 'type' and 'content', type being scene heading, dialogue, or action, and content being the item from ListString(listy).</p>
  <p>And then I add the map to ListMap(fountain) and set it as listview data.</p>
  <p>The problem I have is that the listview does not show all items. When I scroll, some items become visible while some go invisible. And the scroll bar on the side does not move, it stays at the top as if I am not scrolling at all.</p>
  <p>At first I thought it was my phone (Samsung J7 Neo), but I also tested the app on a Samsung S10+, and problem still persists.</p>
  <p>Please help me out. What could be the problem?</p>
  <p>NB: I am using Sketchware to develop my app, not Android Studio.</p>
  <p>This is the XML code for the fragment.</p>
  <pre><code>&lt;LinearLayout
  
      xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;
  
      xmlns:app=&quot;http://schemas.android.com/apk/res-auto&quot;
      xmlns:tools=&quot;http://schemas.android.com/tools&quot;
      android:layout_width=&quot;match_parent&quot;
      android:layout_height=&quot;match_parent&quot;
      android:orientation=&quot;vertical&quot;&gt;
      &lt;ListView
          android:id=&quot;@+id/lv&quot;
          android:layout_width=&quot;match_parent&quot;
          android:layout_height=&quot;wrap_content&quot;
          android:dividerHeight=&quot;3dp&quot;
          android:choiceMode=&quot;none&quot;
          android:layout_weight=&quot;1&quot;
          android:divider=&quot;@android:color/transparent&quot;/&gt;
  &lt;/LinearLayout&gt;
  </code></pre>
  <p>And this is the ReadScriptFragmentActivity.java</p>
  <pre><code>public class ReadscriptFragmentActivity extends  Fragment  { 
      
      
      private HashMap&lt;String, Object&gt; map = new HashMap&lt;&gt;();
      private String path = &quot;&quot;;
      private String SCRIPT = &quot;&quot;;
      private double pos = 0;
      private HashMap&lt;String, Object&gt; map2 = new HashMap&lt;&gt;();
      private String item1 = &quot;&quot;;
      private boolean isUpperCaseOnly = false;
      private double pos1 = 0;
      private String character = &quot;&quot;;
      private String item2 = &quot;&quot;;
      private String typeBind = &quot;&quot;;
      
      private ArrayList&lt;String&gt; listy = new ArrayList&lt;&gt;();
      private ArrayList&lt;HashMap&lt;String, Object&gt;&gt; fountain = new ArrayList&lt;&gt;();
      private ArrayList&lt;String&gt; listy2 = new ArrayList&lt;&gt;();
      
      private ListView lv;
      
      private SharedPreferences sp;
      private SharedPreferences script;
      private Notification not;
      @NonNull
      @Override
      public View onCreateView(@NonNull LayoutInflater _inflater, @Nullable ViewGroup _container, @Nullable Bundle _savedInstanceState) {
          View _view = _inflater.inflate(R.layout.readscript_fragment, _container, false);
          initialize(_savedInstanceState, _view);
          initializeLogic();
          return _view;
      }
      
      private void initialize(Bundle _savedInstanceState, View _view) {
          
          lv = (ListView) _view.findViewById(R.id.lv);
          sp = getContext().getSharedPreferences(&quot;sp&quot;, Activity.MODE_PRIVATE);
          script = getContext().getSharedPreferences(&quot;script&quot;, Activity.MODE_PRIVATE);
      }
      
      private void initializeLogic() {
          _getScript();
      }
      
      @Override
      public void onActivityResult(int _requestCode, int _resultCode, Intent _data) {
          
          super.onActivityResult(_requestCode, _resultCode, _data);
          
          switch (_requestCode) {
              
              default:
              break;
          }
      }
      
      @Override
      public void onResume() {
          super.onResume();
          _getScript();
      }
      public void _getScript () {
          path = script.getString(&quot;path&quot;, &quot;&quot;);
          if (path.equals(&quot;&quot;)) {
              SketchwareUtil.showMessage(getContext(), &quot;Error Opening Script!&quot;);
          }
          else {
              if (FileUtil.readFile(path).equals(&quot;&quot;)) {
                  SketchwareUtil.showMessage(getContext(), &quot;Error Opening Script!&quot;);
              }
              else {
                  map = new Gson().fromJson(FileUtil.readFile(path), new TypeToken&lt;HashMap&lt;String, Object&gt;&gt;(){}.getType());
                  SCRIPT = map.get(&quot;script&quot;).toString();
                  listy = new ArrayList&lt;String&gt;(Arrays.asList(SCRIPT.split(&quot;\n\n&quot;)));
                  lv.setAdapter(new ArrayAdapter&lt;String&gt;(getContext(), android.R.layout.simple_list_item_1, listy));
                  pos = 0;
                  for(int _repeat35 = 0; _repeat35 &lt; (int)(listy.size()); _repeat35++) {
                      item1 = listy.get((int)(pos));
                      if (item1.contains(&quot;\n&quot;)) {
                          item2 = item1.substring((int)(0), (int)(item1.indexOf(&quot;\n&quot;) - 1));
                          if (item2.equals(item2.toUpperCase())) {
                              map2 = new HashMap&lt;&gt;();
                              map2.put(&quot;type&quot;, &quot;dialogue&quot;);
                              map2.put(&quot;content&quot;, &quot;          &quot;.concat(item1));
                              fountain.add(map2);
                          }
                          else {
                              map2 = new HashMap&lt;&gt;();
                              map2.put(&quot;type&quot;, &quot;action&quot;);
                              map2.put(&quot;content&quot;, item1);
                              fountain.add(map2);
                          }
                      }
                      else {
                          if (item1.equals(item1.toUpperCase())) {
                              if (item1.startsWith(&quot;INT.&quot;) || item1.startsWith(&quot;EXT.&quot;)) {
                                  map2 = new HashMap&lt;&gt;();
                                  map2.put(&quot;type&quot;, &quot;scene&quot;);
                                  map2.put(&quot;content&quot;, item1);
                                  fountain.add(map2);
                              }
                              else {
                                  map2 = new HashMap&lt;&gt;();
                                  map2.put(&quot;type&quot;, &quot;action&quot;);
                                  map2.put(&quot;content&quot;, item1);
                                  fountain.add(map2);
                              }
                          }
                          else {
                              map2 = new HashMap&lt;&gt;();
                              map2.put(&quot;type&quot;, &quot;action&quot;);
                              map2.put(&quot;content&quot;, item1);
                              fountain.add(map2);
                          }
                      }
                      pos++;
                  }
              }
          }
          lv.setAdapter(new LvAdapter(fountain));
      }
      
      
      public class LvAdapter extends BaseAdapter {
          ArrayList&lt;HashMap&lt;String, Object&gt;&gt; _data;
          public LvAdapter(ArrayList&lt;HashMap&lt;String, Object&gt;&gt; _arr) {
              _data = _arr;
          }
          
          @Override
          public int getCount() {
              return _data.size();
          }
          
          @Override
          public HashMap&lt;String, Object&gt; getItem(int _index) {
              return _data.get(_index);
          }
          
          @Override
          public long getItemId(int _index) {
              return _index;
          }
          @Override
          public View getView(final int _position, View _v, ViewGroup _container) {
              LayoutInflater _inflater = (LayoutInflater)getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
              View _view = _v;
              if (_view == null) {
                  _view = _inflater.inflate(R.layout.scriptreaditem, null);
              }
              
              final LinearLayout all = (LinearLayout) _view.findViewById(R.id.all);
              final TextView scene = (TextView) _view.findViewById(R.id.scene);
              final TextView action = (TextView) _view.findViewById(R.id.action);
              final TextView dialogue = (TextView) _view.findViewById(R.id.dialogue);
              
              typeBind = _data.get((int)_position).get(&quot;type&quot;).toString();
              if (typeBind.equals(&quot;scene&quot;)) {
                  action.setVisibility(View.GONE);
                  dialogue.setVisibility(View.GONE);
                  scene.setText(_data.get((int)_position).get(&quot;content&quot;).toString());
                  scene.setTypeface(Typeface.createFromAsset(getContext().getAssets(),&quot;fonts/courier_prime_regular.ttf&quot;), 1);
              }
              if (typeBind.equals(&quot;action&quot;)) {
                  scene.setVisibility(View.GONE);
                  dialogue.setVisibility(View.GONE);
                  action.setText(_data.get((int)_position).get(&quot;content&quot;).toString());
                  action.setTypeface(Typeface.createFromAsset(getContext().getAssets(),&quot;fonts/courier_prime_regular.ttf&quot;), 0);
              }
              if (typeBind.equals(&quot;dialogue&quot;)) {
                  scene.setVisibility(View.GONE);
                  action.setVisibility(View.GONE);
                  dialogue.setText(_data.get((int)_position).get(&quot;content&quot;).toString());
                  dialogue.setTypeface(Typeface.createFromAsset(getContext().getAssets(),&quot;fonts/courier_prime_regular.ttf&quot;), 0);
              }
              
              return _view;
          }
      }
  }
  </code></pre>
  <p>Please help. I am not sure what the problem could be. I am not a developer. I learned Java through Sketchware. So please be patient with me. Thank you in advance.</p>
  <p>EDIT: I figured out the problem. If you look at the ListView onBindCustomView, there are three if statements that I added to check if an item is a dialogue, scene heading, or action. The problem is that I added separate if statements for each of them. So what I did was put them in an if-else statement, as in if item is scene, then format as scene, else if item is action, format as action, else if item is dialogue, format as dialogue. So in short, I put the other if statements under the &quot;else&quot; section of the previous if statement. (Sorry if my english is bad). Here is the new updated code.
  public class ReadscriptFragmentActivity extends  Fragment  {</p>
  <pre><code>private HashMap&lt;String, Object&gt; map = new HashMap&lt;&gt;();
  private String path = &quot;&quot;;
  private String SCRIPT = &quot;&quot;;
  private double pos = 0;
  private HashMap&lt;String, Object&gt; map2 = new HashMap&lt;&gt;();
  private String item1 = &quot;&quot;;
  private boolean isUpperCaseOnly = false;
  private double pos1 = 0;
  private String character = &quot;&quot;;
  private String item2 = &quot;&quot;;
  private String typeBind = &quot;&quot;;
  
  private ArrayList&lt;String&gt; listy = new ArrayList&lt;&gt;();
  private ArrayList&lt;HashMap&lt;String, Object&gt;&gt; fountain = new ArrayList&lt;&gt;();
  private ArrayList&lt;String&gt; listy2 = new ArrayList&lt;&gt;();
  
  private ListView lv;
  
  private SharedPreferences sp;
  private SharedPreferences script;
  private Notification not;
  @NonNull
  @Override
  public View onCreateView(@NonNull LayoutInflater _inflater, @Nullable ViewGroup _container, @Nullable Bundle _savedInstanceState) {
      View _view = _inflater.inflate(R.layout.readscript_fragment, _container, false);
      initialize(_savedInstanceState, _view);
      initializeLogic();
      return _view;
  }
  
  private void initialize(Bundle _savedInstanceState, View _view) {
      
      lv = (ListView) _view.findViewById(R.id.lv);
      sp = getContext().getSharedPreferences(&quot;sp&quot;, Activity.MODE_PRIVATE);
      script = getContext().getSharedPreferences(&quot;script&quot;, Activity.MODE_PRIVATE);
  }
  
  private void initializeLogic() {
      _getScript();
  }
  
  @Override
  public void onActivityResult(int _requestCode, int _resultCode, Intent _data) {
      
      super.onActivityResult(_requestCode, _resultCode, _data);
      
      switch (_requestCode) {
          
          default:
          break;
      }
  }
  
  @Override
  public void onResume() {
      super.onResume();
      _getScript();
  }
  public void _getScript () {
      path = script.getString(&quot;path&quot;, &quot;&quot;);
      if (path.equals(&quot;&quot;)) {
          SketchwareUtil.showMessage(getContext(), &quot;Error Opening Script!&quot;);
      }
      else {
          if (FileUtil.readFile(path).equals(&quot;&quot;)) {
              SketchwareUtil.showMessage(getContext(), &quot;Error Opening Script!&quot;);
          }
          else {
              map = new Gson().fromJson(FileUtil.readFile(path), new TypeToken&lt;HashMap&lt;String, Object&gt;&gt;(){}.getType());
              SCRIPT = map.get(&quot;script&quot;).toString();
              listy = new ArrayList&lt;String&gt;(Arrays.asList(SCRIPT.split(&quot;\n\n&quot;)));
              pos = 0;
              for(int _repeat35 = 0; _repeat35 &lt; (int)(listy.size()); _repeat35++) {
                  item1 = listy.get((int)(pos));
                  if (item1.contains(&quot;\n&quot;)) {
                      item2 = item1.substring((int)(0), (int)(item1.indexOf(&quot;\n&quot;) - 1));
                      if (item2.equals(item2.toUpperCase())) {
                          map2 = new HashMap&lt;&gt;();
                          map2.put(&quot;type&quot;, &quot;dialogue&quot;);
                          map2.put(&quot;content&quot;, &quot;          &quot;.concat(item1));
                          fountain.add(map2);
                      }
                      else {
                          map2 = new HashMap&lt;&gt;();
                          map2.put(&quot;type&quot;, &quot;action&quot;);
                          map2.put(&quot;content&quot;, item1);
                          fountain.add(map2);
                      }
                  }
                  else {
                      if (item1.equals(item1.toUpperCase())) {
                          if (item1.startsWith(&quot;INT.&quot;) || item1.startsWith(&quot;EXT.&quot;)) {
                              map2 = new HashMap&lt;&gt;();
                              map2.put(&quot;type&quot;, &quot;scene&quot;);
                              map2.put(&quot;content&quot;, item1);
                              fountain.add(map2);
                          }
                          else {
                              map2 = new HashMap&lt;&gt;();
                              map2.put(&quot;type&quot;, &quot;action&quot;);
                              map2.put(&quot;content&quot;, item1);
                              fountain.add(map2);
                          }
                      }
                      else {
                          map2 = new HashMap&lt;&gt;();
                          map2.put(&quot;type&quot;, &quot;action&quot;);
                          map2.put(&quot;content&quot;, item1);
                          fountain.add(map2);
                      }
                  }
                  pos++;
              }
          }
      }
      lv.setAdapter(new LvAdapter(fountain));
  }
  
  
  public class LvAdapter extends BaseAdapter {
      ArrayList&lt;HashMap&lt;String, Object&gt;&gt; _data;
      public LvAdapter(ArrayList&lt;HashMap&lt;String, Object&gt;&gt; _arr) {
          _data = _arr;
      }
      
      @Override
      public int getCount() {
          return _data.size();
      }
      
      @Override
      public HashMap&lt;String, Object&gt; getItem(int _index) {
          return _data.get(_index);
      }
      
      @Override
      public long getItemId(int _index) {
          return _index;
      }
      @Override
      public View getView(final int _position, View _v, ViewGroup _container) {
          LayoutInflater _inflater = (LayoutInflater)getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
          View _view = _v;
          if (_view == null) {
              _view = _inflater.inflate(R.layout.scriptreaditem, null);
          }
          
          final LinearLayout all = (LinearLayout) _view.findViewById(R.id.all);
          final TextView scene = (TextView) _view.findViewById(R.id.scene);
          final TextView action = (TextView) _view.findViewById(R.id.action);
          final TextView dialogue = (TextView) _view.findViewById(R.id.dialogue);
          
          scene.setTypeface(Typeface.createFromAsset(getContext().getAssets(),&quot;fonts/courier_prime_regular.ttf&quot;), 1);
          action.setTypeface(Typeface.createFromAsset(getContext().getAssets(),&quot;fonts/courier_prime_regular.ttf&quot;), 0);
          dialogue.setTypeface(Typeface.createFromAsset(getContext().getAssets(),&quot;fonts/courier_prime_regular.ttf&quot;), 0);
          typeBind = _data.get((int)_position).get(&quot;type&quot;).toString();
          if (typeBind.equals(&quot;scene&quot;)) {
              action.setVisibility(View.GONE);
              dialogue.setVisibility(View.GONE);
              scene.setVisibility(View.VISIBLE);
              scene.setText(_data.get((int)_position).get(&quot;content&quot;).toString());
          }
          else {
              if (typeBind.equals(&quot;action&quot;)) {
                  scene.setVisibility(View.GONE);
                  dialogue.setVisibility(View.GONE);
                  action.setVisibility(View.VISIBLE);
                  action.setText(_data.get((int)_position).get(&quot;content&quot;).toString());
              }
              else {
                  if (typeBind.equals(&quot;dialogue&quot;)) {
                      scene.setVisibility(View.GONE);
                      action.setVisibility(View.GONE);
                      dialogue.setVisibility(View.VISIBLE);
                      dialogue.setText(_data.get((int)_position).get(&quot;content&quot;).toString());
                  }
              }
          }
          
          return _view;
      }
  }
  </code></pre>
  <p>}</p>
  <p>Thanks to those who responded. I guess this question is answered now. Cheers.</p>