0

I want to display the data from content provider in gridview more than 3 sub items or line

here is my java source code

@Override
public void onLoadFinished(Loader<Cursor> arg0, Cursor cursor) {

    players.clear();
    // First Check if cursor is not null
    if(cursor != null ) {


        StringBuilder result = new StringBuilder();

        // Now loop to all items and append it to string builder
             while (cursor.moveToNext()) {

                String id = cursor.getString(cursor.getColumnIndex("ID"));
                String name = cursor.getString(cursor.getColumnIndex("ITEM_NAME"));
                String qty = cursor.getString(cursor.getColumnIndex("QUANTITY"));
                String inst = cursor.getString(cursor.getColumnIndex("INSTRUCTION"));
                String pid = cursor.getString(cursor.getColumnIndex("POS_ID"));

                players.add("Items :" + name + "\n" + "Qty :" + qty + "\n" +
                             "Details :" + inst + "\n" + " Pos ID :" + pid);


                gv.setAdapter(adapter);
                resultView.setText(result);
            }

    } else {
        // If cursor is null then display toast amd set empty data.
        resultView.setText("Empty data");
        Toast.makeText(MainActivity.this, "May be there is no app  corresponding to your provider or there is null data.",
                        Toast.LENGTH_LONG).show();
    }

}

the gv.setAdapter(adapter) is where i display the data coming from the content provider

and here is my xml source code

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#ffffff"
android:fillViewport="true"
tools:context="com.condorpos.kitchen_bumpbar.MainActivity">

<LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    android:padding="5dp">

<Button
    android:id="@+id/btnRetrieve"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_margin="5dp"
    android:padding="5dp"
    android:text="@string/show_data" />

    <TextView
        android:id="@+id/result"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_margin="5dp"
        android:clickable="false"
        android:padding="5dp"
        android:textColor="#000000"
        android:textSize="15sp" />

    <GridView
        android:layout_width="match_parent"
        android:layout_height="420dp"
        android:numColumns="5"
        android:verticalSpacing="140dp"
        android:id="@+id/gridView1"/>

        <android.support.v7.widget.RecyclerView
            android:id="@+id/expListView"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="1"
            android:visibility="invisible" />

        <TextView
            android:id="@+id/empty_view"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:gravity="center"
            android:visibility="gone"
            android:text="@string/empty_list"
            android:layout_marginLeft="8dp"
            android:layout_marginRight="8dp"/>

   </LinearLayout>
</LinearLayout>

the gridView1 is equals to gv on the java source code i declare it like

Griview gv;

gv=(GridView) findViewById(R.id.gridView1);

from the image below it shows that the data is not fully display looked per column i want to display more than 3 lines but it gives me this result

Displayed data

Any idea or help will do Thanks a lot guys

1 Answers1

2

You need make height of GridView is match_parent/wrap_content (based on your layout), don't fix size 420dp

RoShan Shan
  • 2,924
  • 1
  • 18
  • 38
  • Thank you but i already tried that before and it gives me the same result.. – mark.bendal.erica Sep 26 '16 at 03:57
  • you try to remove recyclerview and textview below(make it gone) – RoShan Shan Sep 26 '16 at 04:04
  • Yes the recyclerview is on invisible mode I hope that is there another way ? to view more than 3 data – mark.bendal.erica Sep 26 '16 at 04:07
  • I searched about GridView, if you set `android:numColumns="auto_fit" android:stretchMode="columnWidth"`, it will affect with match_parent, but if you set numColumns, it won't affect. Could you set numColumns manually by code `gridView.setNumColumns(numColumns` – RoShan Shan Sep 26 '16 at 04:18
  • You can use this solutions [http://stackoverflow.com/questions/8481844/gridview-height-gets-cut/8483078#8483078]http://stackoverflow.com/questions/8481844/gridview-height-gets-cut/8483078#8483078. But I suggest you use recyclerview with and set layutmanager `GridLayoutManager` – RoShan Shan Sep 26 '16 at 04:22