2016-09-26 45 views
0

我想在GridView中超過3個項目或線顯示來自內容提供商的數據超過3個項目每個子項的GridView的Android

這裏是我的Java源代碼

@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(); 
    } 

} 

的GV。 setAdapter(適配器),其中i顯示來自內容提供商

這裏來的數據是我的XML源代碼

<?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> 

的gridView1是等於GV上的Java源代碼我聲明它像

Griview gv; 

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

從圖像下方示出了數據未完全顯示每列看着我想顯示超過3行,但它給了我這樣的結果

Displayed data

任何想法或幫助將做 非常感謝球員

回答

2

你需要做的高度0是match_parent/wrap_content(根據您的佈局),不固定大小420dp

+0

謝謝,但我已經嘗試過,它給了我相同的結果。 –

+0

你試圖刪除recyclerview和textview下面(讓它消失) –

+0

是的recyclerview是在隱形模式我希望有另一種方式?查看3個以上的數據 –