AIDE Tutorial - 16 Grid View Layout
Xml
<GridView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:numColumns="auto_fit"
android:columnWidth="70dp"
android:id="@+id/gv">
</GridView>
Java
package com.kc.gv;
import android.app.*;
import android.os.*;
import android.widget.*;
public class MainActivity extends Activity
{
static final String [] letter= new String[]{
"A", "B", "C", "D", "E",
"F", "G", "H", "I", "J",
"K", "L", "M", "N", "O",
"P", "Q", "R", "S", "T",
"U", "V", "W", "X", "Y",
"Z",
};
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
GridView gv=(GridView)findViewById(R.id.gv);
ArrayAdapter<String> show=new ArrayAdapter<String>(
this,
android.R.layout.simple_list_item_1,
letter
);
gv.setAdapter(show);
}
}
import android.os.*;
import android.widget.*;
public class MainActivity extends Activity
{
static final String [] letter= new String[]{
"A", "B", "C", "D", "E",
"F", "G", "H", "I", "J",
"K", "L", "M", "N", "O",
"P", "Q", "R", "S", "T",
"U", "V", "W", "X", "Y",
"Z",
};
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
GridView gv=(GridView)findViewById(R.id.gv);
ArrayAdapter<String> show=new ArrayAdapter<String>(
this,
android.R.layout.simple_list_item_1,
letter
);
gv.setAdapter(show);
}
}
0 comments:
Post a Comment