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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T19:19:17+00:00 2026-06-02T19:19:17+00:00

I am building a dynamic view in a non-activity class, which is called by

  • 0

I am building a dynamic view in a non-activity class, which is called by my activity class to populate a section of my main view. My problem occurs within this “sub view”

I have an onclicklistener which adds items to a listview, but I cannot call notifydatasetchanged on the adapter from the onclicklistener, because the adapter object needs to be declared final, which won’t work.

What am I doing wrong?

Here’s my code: (I would like to notifydatasetchanged right after newComment(o) )

public  RelativeLayout getCommentsView(final Object o) {
    RelativeLayout view = new RelativeLayout(mContext);
        ImageView background = new ImageView(mContext);
        background.setImageResource(R.drawable.background);
        background.setScaleType(ScaleType.FIT_START);
        LinearLayout comments = new LinearLayout(mContext);
            comments.setOrientation(LinearLayout.VERTICAL);
            comments.setPadding(8,20,8,0);
            LinearLayout titleBar = new LinearLayout(mContext);
                ImageView addButton = new ImageView(mContext);
                addButton.setImageResource(R.drawable.ic_menu_add);
                titleBar.setClickable(true);
                titleBar.setOnClickListener( new OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        newComment(o);
                    }
                });
                TextView title = new TextView(mContext);
                title.setText(mContext.getString(R.string.comments));
                title.setPadding(10,5,0,0);
                title.setTextSize(18);
                title.setTextColor(Color.WHITE);
                if (mContext instanceof LocationActivity) {
                    title.setTextColor(Color.parseColor("#33b5e5"));
                } else if (mContext instanceof TrailActivity) {
                    title.setTextColor(Color.parseColor("#AA66CC"));
                }
                LinearLayout.LayoutParams layout = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,LinearLayout.LayoutParams.WRAP_CONTENT);
                titleBar.addView(title,layout);
                layout = new LinearLayout.LayoutParams(48,48);
                titleBar.addView(addButton,layout);
            TextView divider = new TextView(mContext);
            divider.setBackgroundResource(R.drawable.divider);
            ListView commentsList = new ListView(mContext);
            commentsList.setBackgroundColor(Color.TRANSPARENT);
            commentsList.setCacheColorHint(Color.TRANSPARENT);
            commentsList.addHeaderView(titleBar);
            commentsList.addFooterView(divider);
            CommentsListAdapter commentsListAdapter = new CommentsListAdapter(mContext,R.layout.comments_list_item,getCommentsFor(o));
            commentsList.setAdapter(commentsListAdapter);
            comments.addView(commentsList);
        view.addView(background);
        view.addView(comments);
    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-02T19:19:19+00:00Added an answer on June 2, 2026 at 7:19 pm

    make your non activity class constructor receive the adapter reference and save it on instance variable in your non activity class.

    Then it can be used everywhere within your class without declaring it final

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

Sidebar

Related Questions

I am currently building a very dynamic table for a list application, which will
I'm building dynamic forms in GWT, but I'm not sure how to dynamically retrieve
I am building a dynamic form in a Cocoa application and am planning to
I am building a RESTful protocol for Dynamic Carpooling applications, for my Computer Science
I'm building a WinForm with quite a few dynamic elements, and I think I'm
It seems to not get past this step: [ 16%] Building CXX object src/CMakeFiles/hphp_runtime_static.dir/lib/system/gen/sys/dynamic_table_func.no.cpp.o
I'm building a dynamic web application in Eclipse using Struts2 and OC4J 10.1.3.3.0. I'm
I have a question regarding building dynamic PDF documents with ABCPDF.dll. I understand the
I'm building a openerp customer module that in tree view, there is a button
I am building a table using a <ui:repeat> tag, and its length is dynamic.

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.