title: listview items not showing up in android
body: <p>I am beginner in Android application development and there might be similiar question on stackoverflow but I am unable to find the exact solution to this problem.I have tried many links on SO. Help Appreciated. Let me know if any other file needs to be uploaded.</p>
  
  <p>Here is the listview output
     <a href="https://i.stack.imgur.com/253bJ.png" rel="nofollow">Listview output</a></p>
  
  <p>I'm pretty sure the items are inserted in the listview because I get the following output when i toast the item at 0.<a href="https://i.stack.imgur.com/Aiopb.png" rel="nofollow">Toast.makeText to display item0 of listview l1</a>
  So no problem with inserting data into listview. the problem probably is in displaying</p>
  
  <pre><code>// fragment_cart layout - where the listview is stored.
  
  &lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:orientation="vertical"&gt;
  
  &lt;ListView
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:id="@+id/listview_cart"
     /&gt;
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p>Cartlist_layout - the structure of listview   </p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;TextView xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"&gt;
  &lt;/TextView&gt;
  </code></pre>
  
  <p>//addtocart_layout</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:orientation="vertical"&gt;
  
  &lt;TextView
      android:text="Total :    Rs"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:id="@+id/textView10"
      android:textSize="20sp"
      android:textStyle="normal|bold"
      android:layout_marginTop="16dp"
      android:layout_below="@+id/textView9"
      android:layout_alignStart="@+id/textView9" /&gt;
  
  &lt;EditText
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:inputType="number"
      android:ems="4"
      android:id="@+id/editText6"
      android:text="1"
      android:layout_alignBaseline="@+id/textView9"
      android:layout_alignBottom="@+id/textView9"
      android:layout_alignStart="@+id/textView11" /&gt;
  
  &lt;TextView
      android:text="0"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:id="@+id/textView11"
      android:textStyle="normal|bold"
      android:textSize="20sp"
      android:layout_alignBaseline="@+id/textView10"
      android:layout_alignBottom="@+id/textView10"
      android:layout_alignParentEnd="true"
      android:layout_marginEnd="142dp" /&gt;
  
  &lt;TextView
      android:text="Quantity"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:id="@+id/textView9"
      android:textSize="20sp"
      android:textStyle="normal|bold"
      android:layout_marginTop="36dp"
      android:layout_below="@+id/textView7"
      android:layout_toStartOf="@+id/textView11"
      android:layout_marginEnd="45dp" /&gt;
  
  &lt;TextView
      android:text="ItemName"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:id="@+id/textView7"
      android:textStyle="normal|bold"
      android:textSize="20sp"
      android:layout_marginTop="95dp"
      android:layout_alignParentTop="true"
      android:layout_toEndOf="@+id/textView10"
      android:layout_marginStart="12dp" /&gt;
  
  &lt;/RelativeLayout&gt;
  </code></pre>
  
  <p>CartDialog - the java file </p>
  
  <pre><code>public class CartDialog extends DialogFragment {
      String item;
      TextView iname,t11;
      EditText qty;
      LayoutInflater inflater;
      View view;
      NumberPicker numberPicker;
      public static int sprice[]={40,50,60,25,30,30,25,25,20,20,20,15,15};
      public String names[]=new String[]{"Item1","Item2","Item3"};
      public ListView l1;
      int i=0;
      List itemName;
      LinearLayout rl;
  
      @NonNull
      @Override
      public Dialog onCreateDialog(Bundle savedInstanceState) {
          inflater=getActivity().getLayoutInflater();
          itemName=new ArrayList();
          view=inflater.inflate(R.layout.addtocart_layout,null);
          rl = (LinearLayout)view.inflate(this.getContext(), R.layout.fragment_cart,null);
          //#s1 This code is for some other functionality.  
          iname=(TextView)view.findViewById(R.id.textView7);
          iname.setText(MyMenu.item1);
          int id=Integer.parseInt(MyMenu.childid);
          qty=(EditText)view.findViewById(R.id.editText6);
          t11=(TextView)view.findViewById(R.id.textView11);
              t11.setText(Integer.toString(Integer.parseInt(qty.getText().toString())*sprice[id]));
      qty.addTextChangedListener(
              new TextWatcher() {
                  int id=Integer.parseInt(MyMenu.childid);
                  @Override
                  public void beforeTextChanged(CharSequence s, int start, int count, int after) {
  
                  }
  
                  @Override
                  public void onTextChanged(CharSequence s, int start, int before, int count) {
  
                  }
  
                  @Override
                  public void afterTextChanged(Editable s) {
                      String qty_value=qty.getText().toString();
                      if(!qty_value.equals(""))
                          t11.setText(Integer.toString(Integer.parseInt(qty_value)*sprice[id]));
                      else
                          t11.setText("");
  
                  }
              }
      );
       #s1 ends here
  
      AlertDialog.Builder builder=new AlertDialog.Builder(getActivity());
      builder.setView(view).setPositiveButton("Add to Cart", new DialogInterface.OnClickListener() {
          @Override
          public void onClick(DialogInterface dialog, int which) {
              onAddToCart();
          }
      }).setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
          @Override
          public void onClick(DialogInterface dialog, int which) {
  
          }
      });
  
      return builder.create();
  }
  public void onAddToCart(){
  //PLAUSIBLE PROBLEM HERE - i think, Something must be wrong here   
      ArrayAdapter&lt;String&gt; adapter1=new ArrayAdapter&lt;String&gt;(this.getContext(),R.layout.cartlist_layout,names);
      l1=(ListView)rl.findViewById(R.id.listview_cart);
      l1.setAdapter(adapter1);
      Toast.makeText(this.getContext(),"Added to Cart:"+l1.getItemAtPosition(0),Toast.LENGTH_SHORT).show();
  }
  }
  </code></pre>