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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T12:10:26+00:00 2026-05-19T12:10:26+00:00

In my Android activity, I create a custom view that extends SurfaceView (using MonoDroid

  • 0

In my Android activity, I create a custom view that extends SurfaceView (using MonoDroid so slight variations in syntax):

class FriendsView : SurfaceView
{
    ...

    public FriendsView(Context context) : base(context)
    {

        ... create my custom view ...

    }


}

In my Activity class, I set the content view to the view:

protected override void OnCreate(Bundle bundle)
{

    base.OnCreate(bundle);

    ViewGroup.LayoutParams layoutParams = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.FillParent, ViewGroup.LayoutParams.FillParent);

    FriendsView friendsView = new FriendsView(this);

    SetContentView(friendsView, layoutParams);

}

I want to add a button to the view, but cannot work out how to do this. Everything I have read starts from the point of view of the main.xml, but I don’t see how to use this to declare a button which is visible in my view. Equally, I cannot find a method in either Activity or View classes which lets me add a Button object programatically.

I feel sure I am missing something conceptually, but would welcome any help to get me going in the right direction.

  • 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-19T12:10:27+00:00Added an answer on May 19, 2026 at 12:10 pm

    If I understand correctly you see your friendsView just fine, but you want to add a button to it?
    I don’t know what kind of View your FriendsView is, but assuming it is something you can add childs to (like a linearLayout or something), you should be able to do this (just from the top of my head)

     //assuming you have a friendsView object that is some sort of Layout.
     Button yourButton = new ImageButton(this);
     //do stuff like add text and listeners.
    
     friendsView.addView(yourButton);
    

    If there is some other element in friendsView you want to add a child to, you can just find it using findViewById() (add ids to your elements if you want to find them like this)

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

Sidebar

Related Questions

I create a custom image view by extending ImageView that just draws some text
I have an Android activity that displays a list of log entries (using a
I want to create a list view custom like this link : http://sites.google.com/site/androideyecontact/_/rsrc/1238086823282/Home/android-eye-contact-lite/eye_contact-list_view_3.png?height=420&width=279 so
Is it possible to create a custom library in Android (having its own layout
I understand the Android OS is based on Linux. Does that mean the G1
I have two threads in an Android application, one is the view thread, and
Now that the G1 with Google's Android OS is now available (soon), will the
I am attempting to create a custom Adapter for my ListView since each item
I want to create a layout in such a way that on top edittext
I created an activity which holds 3 custom components (defined in xml). 2 components

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.