Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7060241
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T04:19:44+00:00 2026-05-28T04:19:44+00:00

Hello dear programmers, I am very new to android application development and for practice

  • 0

Hello dear programmers,
I am very new to android application development and for practice I tried to develope an application with following code

     package com.android.practice;

    import android.content.Context;
    import android.view.View;
    import android.view.ViewGroup;
    import android.widget.BaseAdapter;
    import android.widget.GridView;
    import android.widget.TextView;



    public class CalculatorAdapter extends BaseAdapter {
        private Context mContext;
        private String[] texts={"1","2","3","+","4","5","6","-","7","8","9","*",".","0","=","/"};
        public CalculatorAdapter(Context context) {
            mContext=context;
        }
        @Override
        public int getCount() {
            return texts.length;
        }
        @Override
        public Object getItem(int position) {
            return null;
        }
        @Override
        public long getItemId(int position) {
            return 0;
        }
        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            TextView tv;
            if(convertView==null){
                tv=new TextView(mContext);
                tv.setLayoutParams(new GridView.LayoutParams(85,85));
            }else{
                tv=(TextView)convertView;
            }
            tv.setText(texts[position]);
            tv.setTextSize(30);
            return tv;
        }

    }



       package com.android.practice;

    import android.app.Activity;
    import android.os.Bundle;
    import android.widget.GridView;

    public class MyCalculatorActivity extends Activity {
        /** Called when the activity is first created. */
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.main);
            GridView gv=(GridView)findViewById(R.id.gridView);
            //gv.setGravity(0x11);
            gv.setAdapter(new CalculatorAdapter(this));

        }
    }


<?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"
    android:weightSum="1">
    <TextView  
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content" 
        android:text="0"
        android:textStyle="bold"
        android:textSize="30px"
        android:gravity="center_horizontal"
        android:background="#aa0000"
    />
    <GridView xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/gridView"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:clickable="true"
        android:numColumns="4"
        android:columnWidth="90dp"
        android:horizontalSpacing="10dp"
        android:verticalSpacing="10dp"
        android:stretchMode="columnWidth"
    />
</LinearLayout>

My problem is though I have given the gridview gravity attribute as center, I am not getting the texts at the center of the cells of my gridview.

Please help me, If somebody finds where the problem lies.

Thanks in advance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T04:19:45+00:00Added an answer on May 28, 2026 at 4:19 am

    Use this

    <TextView   
    android:gravity="center_vertical|center_horizontal"  />
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hello I am trying to create a stacked barplot using the following code: test
Hello all i got a mail code like this body = Dear & cName
Hello I have the following code to retrieve data from my db using nhibernate
Hello all in my iphone application after sending login xml request am getting following
Hello dear programmers, I have a requirement for creating a custom tableviewcell with a
Hello Dear StackOverflowers, I am new to web programming and finding the server-client mixture
Hello I have the following error by git-fsck, which cannot be cleaned by git-gc
Hello again ladies and gents! OK, following on from my other question on ASP.NET
Hello there and Merry Christmas !!! I am new to WPF and I am
Hello we have an SQL server application running over a low bandwith connection. We

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.