GridView Application

GridView application represent the data in the form of row and column.

Step 1.

Create new application with any name from file menu option.
File → New Project → Application name → select API → Add Blank Activity → Activity Name → finish

Step 2.

In activity_main.xml layout file design your application.
Add following Controls:-

Step 3.

Import Package and write following coding in class file.

    import android.view.View;
    import android.widget.AdapterView;
    import android.widget.ArrayAdapter;
    import android.widget.GridView;
    import android.widget.TextView;
    import android.widget.Toast;

  public class MainActivity extends ActionBarActivity {

    GridView gd;
    String []arr={"Akhtar","Manzar","Hussainn","Raza","hello","A","B","C"};
    protected void onCreate(Bundle savedInstanceState) {
        ArrayAdapter<String> adp=new ArrayAdapter<String>
        gd.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {

        String data=((TextView)view).getText().toString()+" is selected";


Step 4. Final Output

grid view
Advertisement here

Share this Page.