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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T11:56:07+00:00 2026-06-05T11:56:07+00:00

What I have here is a custom view and then I want some widgets

  • 0

What I have here is a custom view and then I want some widgets to go with it.

<com.zone.manager.Tab3
    android:id="@+id/tab3_display"
    android:layout_width="fill_parent"
    android:layout_height="620dp" >

<Button
    android:id="@+id/addZone"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Add Zone" />

</com.zone.manager.Tab3>

Now I want to have that button set to onclicklistener so I can do stuff with it in the View class so I did this…

addZone = (Button) findViewById(R.id.addZone);


  addZone.setOnClickListener(this);

I set that in the

public class Tab3 extends ViewGroup implements OnTouchListener, OnClickListener
    Public Tab3(Context context, AttributeSet attrs) 
    {
    super (context, attrs); 
    // here
    }

When I extended ViewGroup it made me implement this

@Override
    protected void onLayout(boolean changed, int l, int t, int r, int b) 
    {
        // TODO Auto-generated method stub

    }

Is there something that I am suppsot to put in here in order to make this work?

But when I try to run the app it crashes, however if I // out the addZone.setOnClickListener(this); the app runs fine, any help for me?

tabs

        th.setup();
        TabSpec specs = th.newTabSpec("tag0");
        specs.setContent(R.id.connecttionTab);
        specs.setIndicator("Connection Tab");
        th.addTab(specs);
        specs = th.newTabSpec("tag1");
        specs.setContent(R.id.tab1);
        specs.setIndicator("Zone Manager");
        th.addTab(specs);
        specs = th.newTabSpec("tag2");
        specs.setContent(R.id.tab2);
        specs.setIndicator("",res.getDrawable(R.drawable.ic_tab_vaccontrol));
        th.addTab(specs);
        //this is the tab that has all this vvv
        specs = th.newTabSpec("tag3");
        specs.setContent(R.id.tab3);
        specs.setIndicator("Graphical Layout");
        th.addTab(specs);
  • 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-05T11:56:09+00:00Added an answer on June 5, 2026 at 11:56 am

    In your xml, your custom view does not contain the button; it is a sibling view. The reason your app crashes is that findViewById(R.id.addZone) is returning null, so you are getting a NullPointerException when you call addZone.setOnClickListener(this). If you want your custom view to contain the button, the xml would have to look something like this:

    <com.zone.manager.Tab3
        android:id="@+id/tab3_display"
        android:layout_width="fill_parent"
        android:layout_height="620dp" >
    
        <Button
            android:id="@+id/addZone"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Add Zone" />
    
    </com.zone.manager.Tab3>
    

    Also, your Tab3 class will have to extend ViewGroup, not View. This can get a bit complicated because you also need to write code to do the layout. The button will also be displayed inside the Tab3 view.

    EDIT

    Based on your comments of what you are trying to do, I do not recommend the above approach. Instead, you should just wrap your custom view and the Button in a LinearLayout. For example, the following layout will put the button at the bottom left of the screen and will have a Tab3 view fill the area above it:

    res/layout.tab3.xml

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical" >
    
        <com.zone.manager.Tab3
            android:id="@+id/tab3_display"
            android:layout_width="fill_parent"
            android:layout_height="0dp"
            android:layout_weight="1" />
    
        <Button
            android:id="@+id/addZone"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:onClick="onAddZone"
            android:text="Add Zone" />
    
    </LinearLayout>
    

    Then, move the click processing logic to a separate method in Tab3 that is visible to your Activity class. (Let’s assume that it is called addZone().) The Tab3 class should not implement OnClickListener and should extend View (not ViewGroup as above). By adding the android:onClick attribute to the button, you don’t need to add an OnClickListener to the button. Instead, you need to implement a click method of that name in the activity:

    private Tab3 mTab3;
    
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.tab3);
        mTab3 = (Tab3) findViewById(R.id.tab3_display);
        // . . .
    }
    
    @Override
    /**
     * Called when a view with attribute android:onClick="onAddZone"
     * is clicked.
     *
     * @param view the view that was clicked.
     */
    public void onAddZone(View view) {
        mTab3.addZone();
    }
    

    Although there is nothing in your code about the button, the framework will automatically wire everything up using reflection so that the onAddZone method of the activity will be called when the button is clicked.

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

Sidebar

Related Questions

I have a custom CMS here entitled phpVMS, and I want to exclude a
Here is my page: http://budclarychevy.com/custom/parts-specials-test My aim is to have the images clickable and
n00b here (first Android project). I have been given a custom video codec that
Here is my custom class that I have that represents a triangle. I'm trying
I have the following property: @property (nonatomic, assign) double lastSynced; and here's my custom
Here's what I have: Custom-made C# CMS where the content is stored in a
Here's my aproach: I have a custom ListView containing a custom Adapter containing two
I have a custom content type create in visual studio 2010: custom http://img204.imageshack.us/img204/439/customf.jpg Here
So here's what I'm trying to do - Using a custom QGraphicsItem, I have
This may be have a better name than custom tab completion, but here's the

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.