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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T12:22:19+00:00 2026-06-14T12:22:19+00:00

I have a problem with my shoping list application. I implemented a button adapter

  • 0

I have a problem with my shoping list application. I implemented a button adapter from this tutorial which I will use for adding products to list. Each buuton in my gridview will be a product and each product will have context menu where I can add it to list or delete the product.

Problem is that user should have ability to add new products or categories and I don’t know how to add items to gridview at runtime. I thought that I could create some dynamic array like list in c++ but i’m new to android and java so I have no idea how to implement something like that.

I tried to implement stack but every time I try to push something app crashes. The same is with array list.

ButtonAdapter :

ButtonAdapter(Context c, ArrayList<String> array){
  mContext = c; 
  arrayInAdapter = array; } 


public int getCount() {  
    int a;
    a = arrayInAdapter.size();
 return a;  
}  

public View getView(int position, View convertView, ViewGroup parent) {  
 Button btn;  

 if (convertView == null) {  
  //if it's not recycled, initialize some attributes  
  btn = new Button(mContext);  
  btn.setLayoutParams(new GridView.LayoutParams(130, 130));  
  btn.setPadding(8, 8, 8, 8);  
 }  
 else {  
 btn = (Button) convertView;  
 }  
 btn.setText(arrayInAdapter.get(position));   
 btn.setTextColor(Color.RED);  
 btn.setBackgroundResource(R.drawable.sample_0);  
 btn.setId(position); 
 btn.setOnClickListener(new MyOnClickListener(position));

 return btn;  
}  

}

and in Grid Activity i have another arraylist

public static ArrayList<String> arrayInGrid;

in onCreate:

gridView.setAdapter(new ButtonAdapter(this,arrayInGrid ));  

but when i try to send new item to array program crashes.

arrayInGrid.add("new");

In fact it crashes at

arrayInAdapter.size();  

in button adapter.

any ideas what is wrong?

  • 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-14T12:22:20+00:00Added an answer on June 14, 2026 at 12:22 pm

    You can pass the values in your dynamic array to the BaseAdapter for that GridView.
    Here’s a tutorial, Hope it will help you.
    http://www.mkyong.com/android/android-gridview-example/

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

Sidebar

Related Questions

I have a list showing up when I click on button, the problem is
Hi i'm facing this problem. I have an application with 2 activities: -Activity A
I have problem with changing this image list provider in to thumbnail provider. In
I have an application which shows a list view. I am planning to make
In my application i have used list view and custom cell which contain product
I am developing an android application in which I have to upload image from
I have problem with my query on C, I’m using the oci8 driver. This
I have problem with show or hide form in Window Form Application. I start
I have problem with UIWebView delay when the load image from url. In my
I have an action Edit in my WPF application, which is bound to items

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.