in xml file:
< pre class="brush: java"< < ?xml version="1.0" encoding="utf-8"?> < 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:id="@+id/gridView1" android:numColumns="auto_fit" android:gravity="center" android:columnWidth="50dp" android:stretchMode="columnWidth" android:layout_width="fill_parent" android:layout_height="fill_parent" > < /GridView> < /LinearLayout>in java file:
public class Gridviewactivity extends Activity { GridView gridView; static final String[] numbers = 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"}; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); gridView=(GridView) findViewById(R.id.gridView1); ArrayAdapteradapter=new ArrayAdapter (this,android.R.layout.simple_list_item_1,numbers); gridView.setAdapter(adapter); gridView.setOnItemClickListener(new OnItemClickListener() { public void onItemClick(AdapterView arg0, View v, int position,long arg3) { Toast.makeText(getApplicationContext(), ((TextView) v).getText()+ "at position"+position, Toast.LENGTH_SHORT).show(); } }); }}
Comments
Post a Comment