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

  • Home
  • SEARCH
  • 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 7797557
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T23:43:20+00:00 2026-06-01T23:43:20+00:00

In my Activity i have: DrawView which is a Custom Relative Layout. This RelativeLayout

  • 0

In my Activity i have:

DrawView which is a Custom Relative Layout.

This RelativeLayout should exist of a Custom Navigationbar and a Custom GridView

The Custom NavigationBar is added here to the DrawView:

final LayoutInflater factory = getLayoutInflater();
        final View textEntryView = factory.inflate(R.layout.multiplechoice, null);
        com.lernapp.src.Views.NavigationBarTest navigation = (com.lernapp.src.Views.NavigationBarTest)textEntryView.findViewById(R.id.navigationbar);
        RelativeLayout parent = (RelativeLayout)navigation.getParent();
        parent.removeAllViews();

        drawView.addView(navigation);

i wanted to do something similar with the GridView..

I dont get it, my CustomGridView is always null, why is this!?

MyCustomGridView grid = (MyCustomGridView)findViewById(R.id.gridview);

xml:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"  
  android:orientation="vertical"  
  android:layout_width="fill_parent"  
  android:layout_height="fill_parent">  

    <com.lernapp.src.Views.MyCustomGridView  
        android:id="@+id/gridview"  
        android:layout_width="fill_parent"  
        android:layout_height="fill_parent"  
        android:cacheColorHint="#00000000"  
        android:listSelector="@android:color/transparent"  
        android:numColumns="auto_fit"  
        android:columnWidth="160dp"/>  
</LinearLayout>

CustomGridView:

public class MyCustomGridView extends GridView implements OnItemClickListener{  
      private Listener mListener;  

      public MyCustomGridView(Context context, AttributeSet attrs) {  
        super(context, attrs);  
        setOnItemClickListener(this);  
      }  

      public void onItemClick(AdapterView parent, View v, int position, long id) {  
        if (mListener != null) {  
          mListener.onClick(position);  
        }  
      }  

      public void setListener(Listener l){  
        mListener = l;  
      }  

      public interface Listener{  
        void onClick(int position);   
      }

    }  

EDIT:

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    int height = this.getWindowManager().getDefaultDisplay().getHeight();
    int width = this.getWindowManager().getDefaultDisplay().getWidth();

    MyCustomGridView grid = (MyCustomGridView)findViewById(R.id.gridview);

    DrawView drawView = new DrawView(this, dragFieldText, targetFieldText, height, width, grid);

    final LayoutInflater factory = getLayoutInflater();
    final View textEntryView = factory.inflate(R.layout.multiplechoice, null);
    com.lernapp.src.Views.NavigationBarTest navigation = (com.lernapp.src.Views.NavigationBarTest)textEntryView.findViewById(R.id.navigationbar);
    RelativeLayout parent = (RelativeLayout)navigation.getParent();
    parent.removeAllViews();

    drawView.addView(navigation);

    setContentView(drawView);       
}
  • 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-01T23:43:23+00:00Added an answer on June 1, 2026 at 11:43 pm

    Add this line to your onCreate and all will be good:

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.the_name_of_the_layout_for_this_activity);
    

    And to be really clear, its

        setContentView(R.layout.the_name_of_the_layout_for_this_activity);
    

    You should add to the onCreate, and it must be added BEFORE you try and do findViewById().

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

Sidebar

Related Questions

I have a custom view called DrawView created in the main activity. I have
I have my main Activity, it starts with a custom SurfaceView called DrawView being
I have an activity which have a method in it. In this method I
I want to make Activity like this using GridView. And this Activity have only
I have an activity which have ListView. When I want to access this ListView
In my activity i have to show some images. I used gridview in my
I am developing an activity which have an Update button as menu for android.
in my app i have activity with XML layout, i want to build an
I am having trouble with my activity management. So I have activity A which
I have an activity which have a button and a listview(with chechbox, image and

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.