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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T00:49:30+00:00 2026-05-25T00:49:30+00:00

Hellow this is my first question in stack. Im creating a dynamic grid of

  • 0

Hellow this is my first question in stack.
Im creating a dynamic grid of this tutorial
http://www.stealthcopter.com/blog/2010/09/android-creating-a-custom-adapter-for-gridview-buttonadapter/comment-page-1/

Now it’s working pretty good. My layout is composed by a gridView and under this gridView i have a TextView.

The problem is that i want to change the TextView to display different information on each id when the focus changes (on the grid elements). I’ve tried to use OnFocusChangeListener inside ButtonAdapter, but when trying to get a reference to the textView, it says that findViewById is not implemented.

I wonder how to make a reference in my main activity that allows me to handle my dynamic grid elements.
I have the following in onCreate();

    GridView gridview = (GridView) findViewById(R.id.gridview);
    gridview.setAdapter(new ButtonAdapter(this));

So i want to handle my grid elements from here, any ideas?
Thanks

Edit:
I’ve been trying to change different things, but im receiving a NullPointerException from my getView method. I can’t find a way to make it work, i’ll apreciate any help guys, this is my code:

    public View getView(int position, View convertView, ViewGroup parent) {
    final Button btn;
    if (convertView == null) {
        // if it's not recycled, initialize some attributes
        btn = new Button(mContext);
        btn.setLayoutParams(new GridView.LayoutParams(100, 55));
        btn.setPadding(8, 8, 8, 8);
    } else {
        btn = (Button) convertView;
    }

    btn.setText(filenames[position]);
    // filenames is an array of strings
    btn.setTextColor(Color.WHITE);
    btn.setId(position);
    btn.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View arg0) {
            TextView vt = (TextView) btn.findViewById(R.id.textView1);
            vt.setText("Button Pressed");
        }
    });

Thanks.

  • 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-25T00:49:31+00:00Added an answer on May 25, 2026 at 12:49 am

    I think you are on the right track, but I think it would make most sense to take care of it in your adapter. So findViewById() isn’t working for you, but it will work if you change it to convertView.findViewById() (or whatever view is returned in your getView method of your Adapter). From there you will be able to manipulate the TextView.

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

Sidebar

Related Questions

So just went through this tutorial: http://icodeblog.com/2010/04/05/ipad-programming-tutorial-hello-world/ Now what I want to do is
First off - hello, this is my first Stack Overflow question so I'll try
This is the first time i'm asking a question here at stack overflow so
Hello this is my first question of stack overflow, so forgive me if i
Hello this is may first question and I have found so far the following
Preamble So, this question has already been answered, but as it was my first
this my first question! I am playing around with the Google slide template that
This is my first post. Please forgive me for asking a basic question as
this is my first time on this forum, so forgive me if my question
this is my first question and I've been messing around with android for just

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.