GridView中没有显示数据

时间:2014-02-12 17:17:53

标签: java android

我正在为我的项目测试GridView。这么好但是gridview没有显示任何数据,请指导我。

public class MainActivity extends Activity {

    TextView msgTV;
    GridView msgGV;
    ArrayAdapter<String>adapter;
    static final String[] items={"data-0","data-1","data-2","data-3","data-4",
                                    "data-5","data-6","data-7","data-8","data-9"
                                };
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initGUI();
        msgGV.setAdapter(adapter);
            }



    private void initGUI()
    {
        msgTV=(TextView)findViewById(R.id.messageTextView);
        msgGV=(GridView)findViewById(R.id.displayGridView);
        adapter=new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,items);
    }

}

follwoing来自我的布局文件 列宽或间距是否有问题

<GridView
            android:id="@+id/displayGridView"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="#FFF"
            android:columnWidth="5dp"
            android:gravity="center"
            android:horizontalSpacing="5dp"
            android:numColumns="auto_fit"
            android:stretchMode="spacingWidth"
            android:verticalSpacing="5dp" >
        </GridView>

0 个答案:

没有答案