In Android we can create our application may represent in Grid view or Listview. In this post i explained android Gridview example.
Java source code for creating gridview.
package in.androidshivendra.listexampleproject;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.widget.ArrayAdapter;
import android.widget.GridView;
public class GridViewExample extends Activity {
String [] abc={"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"};
GridView gv;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_grid_view_example);
GridView gv = (GridView)findViewById(R.id.gridView1);
ArrayAdapteradp=new ArrayAdapter(GridViewExample.this,
android.R.layout.simple_list_item_1,City);
gv.setAdapter(adp);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.grid_view_example, menu);
return true;
}
}
Activity layout code:
create activity_grid_view_example.xml in layout folder.
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/LinearLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".GridViewExample" >
No comments:
Post a Comment