Android将listview转换为GridView

时间:2015-05-25 04:41:42

标签: android listview gridview

以下代码在ListView中工作正常,我花了几天时间仍然不知道如何将其转换为GridView。首先,我尝试将ListView替换为GridView,但失败了。有人可以帮忙吗?

5 个答案:

答案 0 :(得分:3)

  

对于这种要求,最好使用'RecyclerView',而不是   listview和gridview,在recylerview中有一个选项   <c:forEach varStatus="loop"> <c:if test="${loop.index >=0 && loop.index <=5}"> </c:if> </c:forEach>

listview的布局管理器:

'recyclerview.setLayoutManager(layoutmanager)'

gridview的LayoutManager:

LinearLayoutManager layoutManager = new LinearLayoutManager(getActivity());

有关详细信息,请参阅  http://www.intertech.com/Blog/android-v5-lollipop-recyclerview-tutorial/

答案 1 :(得分:0)

(char **a, char **b)

答案 2 :(得分:0)

%.rc: $(BITMAPS)
    $(file > $@.rc, $^)

<?xml version="1.0" encoding="utf-8"?>//    gridView.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">

<GridView 
    android:layout_height="wrap_content" 
    android:id="@+id/gridView1" 
    android:layout_width="match_parent" 
    android:numColumns="2"
    android:horizontalSpacing="10dp"
    android:verticalSpacing="10dp">
</GridView>

答案 3 :(得分:0)

除了用GridView替换ListView之外,还应该添加一个属性来获取GridView。

即,

android:numColumns="auto_fit"

也会在您的java文件中用GridView替换ListView。

答案 4 :(得分:0)

我改变了这条线 SimpleAdapter adapter = new SimpleAdapter(getBaseContext(),countries,R.layout.lv_layout,from,to);

SimpleAdapter adapter = new SimpleAdapter(getBaseContext(),countries,R.layout.grid_view_item,new String [] {&#34; flag&#34;,&#34; foodname&#34;,&#34; fooddesc1&# 34;,&#34; foodprice&#34;},new int [] {R.id.imageView1,R.id.textView1,R.id.textView2,R.id.textView3});

现在工作正常。非常感谢!