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 9237085
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T07:27:17+00:00 2026-06-18T07:27:17+00:00

This is where I am stuck now. I am stuck at dynamically adding buttons

  • 0

This is where I am stuck now. I am stuck at dynamically adding buttons to gridview.
– My gridview stars with a one button.
– When user clicks that button a context menu , pops up, asking user to enter info, once that is done. A block in the grid view is created with that info
– This is shown in the picture

I have pasted the code. I do not have clear idea on how to do it. I am assuming it will be inflating a new view and adding it to parent(layout or grid ?) view. I do not have much idea on how to code it. I have tried many things from google. I thought I could start from simple image gridview and modify it to my needs but it did not work.

Please provide some directions.

enter image description here

create_team_new.xml(layout where gridview resides)

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    android:id="@+id/parentcreateteam"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    xmlns:android="http://schemas.android.com/apk/res/android"
     android:background="@drawable/background">

<TextView
    android:id="@+id/citytextview"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/city"
    android:layout_alignTop="@+id/teamcity"
    android:layout_alignParentLeft="true" />

<AutoCompleteTextView
    android:id="@+id/teamname"
    android:layout_width="244dp"
    android:layout_height="wrap_content"
    android:layout_alignLeft="@+id/teamcity"
    android:layout_alignRight="@+id/gridviewplayer"
    android:text="@string/teamname"
    android:textSize="18sp" >
<requestFocus />
</AutoCompleteTextView>
<Button
    android:id="@+id/createteam"
    android:layout_width="140dp"
    android:layout_height="wrap_content"
    android:text="Create Team"
    android:layout_alignParentBottom="true"
    android:layout_centerHorizontal="true"
     android:background="@drawable/red_button"
          style="@+style/button_text" />

<TextView
    android:id="@+id/teamnametextview"
    android:layout_width="wrap_content"
    android:layout_height="22dp"
    android:layout_alignBaseline="@+id/teamname"
    android:layout_alignBottom="@+id/teamname"
    android:layout_alignParentLeft="true"
    android:text="@string/teamname" />

<AutoCompleteTextView
    android:id="@+id/teamcity"
    android:layout_width="244dp"
    android:layout_height="wrap_content"
    android:layout_alignLeft="@+id/cricket"
    android:layout_alignRight="@+id/gridviewplayer"
    android:layout_below="@+id/teamname"
    android:layout_marginTop="22dp"
    android:ems="10"
    android:text="@string/city"
    android:textSize="18sp" >


</AutoCompleteTextView>

<TextView
    android:id="@+id/radiotextview"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_below="@+id/teamcity"
    android:layout_marginTop="15dp"
    android:text="Pick a Sport" />


<GridView
    android:id="@+id/gridviewplayer"
    android:layout_width="match_parent"
    android:layout_height="170dp"
    android:layout_above="@+id/createteam"
    android:layout_below="@+id/pick_sport"
    android:layout_centerHorizontal="true"
    android:background="@drawable/gv_bkg"
 android:padding="5dp"
    android:numColumns="4" >

</GridView>



<RadioGroup
    android:id="@+id/pick_sport"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"

    android:layout_alignRight="@+id/createteam"
    android:layout_below="@+id/radiotextview"
    android:orientation="horizontal" >

    <RadioButton
        android:id="@+id/cricket"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Cricket" />

    <RadioButton
        android:id="@+id/soccer"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Soccer" />
</RadioGroup>

</RelativeLayout>

gv_createplayer.xml(view to be inflated inside gridview)

<?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"
    >

<Button  android:id="@+id/btn_player"
    android:layout_width="match_parent"

    android:layout_height="wrap_content"

    android:text= "+"

    android:background="@drawable/red_button">

</Button>
</LinearLayout>

PlayerAdapter.java(gridview Adapter)

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.GridView;
import android.widget.ImageView;

public class PlayerAdapter extends BaseAdapter {

    private Context mContext;
    LayoutInflater inflater;

    // Keep all Images in array
    public Integer[] mThumbIds = {};
        /*  R.drawable.gridview_createteam, R.drawable.pic2,
            R.drawable.pic3, R.drawable.pic4,
            R.drawable.pic5, R.drawable.pic6,
            R.drawable.pic7, R.drawable.pic8,
            R.drawable.pic9, R.drawable.pic10,
            R.drawable.pic11, R.drawable.pic12,
            R.drawable.pic13, R.drawable.pic14,
            R.drawable.pic15
    };
*/
    // Constructor
    public PlayerAdapter(Context c){
        mContext = c;
    }

    @Override
    public int getCount() {
        return mThumbIds.length;
    }

    @Override
    public Object getItem(int position) {
        return mThumbIds[position];
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @SuppressWarnings("static-access")
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View view = new View(mContext);
        view.inflate(mContext, R.layout.gv_createplayer,null);

        return view;


    }


}
  • 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-06-18T07:27:18+00:00Added an answer on June 18, 2026 at 7:27 am

    1) How to create a list view inside a main view, only using a half of the screen.

    This is done by the weight attribute. A rough example for your sketch: The top wrapper (edittexts and buttons) has a weight of .45, the listview has a weight of .45 and the footer has a weight of .1. You can specify the weight-sum in the surrounding view; but default should be 1.

    2) How to populate list view in grid manner (a row of two columns will repeat itself)

    Well, with the GridView (the adapter API is the same) (:

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have now been stuck at this for some time so I though to
I have been stuck on this for a while now and I cannot seem
I am currently stuck at this problem right now where I don't seem to
I've been stuck with this for weeks now and have no idea where I'm
so i have been stuck with this issue for 3 weeks now and i
I've been stuck on this for a couple of days now, and I'm really
Ok, so I've been stuck on this for about three hours now and I
I've been stuck with this for hours now. I think it's time for some
I've come a bit stuck this afternoon with a bug in my web application
Been stuck on this for ages. Currently learning Django and done some bits on

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.