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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T18:22:26+00:00 2026-06-06T18:22:26+00:00

I’m learning Android and I’ve done a custom control. When I put it in

  • 0

I’m learning Android and I’ve done a custom control. When I put it in a Layout, it works fine. I put it in this way in itemduplicados.xml:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >
    <com.android.customViews.CtlDuplicado
        android:id="@+id/dupCancion"
        android:layout_width="match_parent"
        android:layout_height="match_parent"/>
</LinearLayout>

Then I want to do a list of many of this controls, so I use a listview in listadoduplicado.xml:

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

<ListView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/LstListadoDuplicados"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

</ListView>
</LinearLayout>

An Activity for this with a onCreate:

public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.listadoduplicados);
        AdaptDuplicados adapter = new AdaptDuplicados(this, Deduplicator.deduplicate());
        final ListView lstDuplicados = (ListView) findViewById(R.id.LstListadoDuplicados);
        lstDuplicados.setAdapter(adapter);
        lstDuplicados.setVisibility(View.VISIBLE);

    }

And then a class that extends arrayadapter to populate the listview with ctlduplicados:

public AdaptDuplicados(Activity context, ArrayList<Duplicado> datos) {
    super(context, R.layout.itemduplicado, datos);
        this.context = context;
        this.datos = datos;
    }
    public View getView(int position, View convertView, ViewGroup parent) {
                View item = convertView;
                DuplicadoViewHolder dvh;
                if (item == null){
                    LayoutInflater li = context.getLayoutInflater();
                    item = li.inflate(R.layout.itemduplicado, null);
                    dvh = new DuplicadoViewHolder();
                    dvh.duplicado = (CtlDuplicado)item.findViewById(R.id.dupCancion);
                    item.setTag(item);
                }else{
                    dvh = (DuplicadoViewHolder)item.getTag();
                }
                dvh.duplicado.setCanciones(datos.get(position));//here is the nullpointerexception cause duplicado is null
                return (item);
            }

Well, the I have a nullpointerexception because dvh.duplicado is null.

Debbuging in eclipse I see that in the line

item = li.inflate(R.layout.itemduplicado, null); 

The item is created and item contains a CtlDuplicado well created in an internal array called mChildren, but when I get item.findViewById(R.id.dupCancion) it returns null…

The R.id.dupCancion is defined in project’s R.

Can someone give me any clue of what is happening?

EDIT: the dvh.duplicado that is null is the one in the ‘if’, this;

 dvh.duplicado = (CtlDuplicado)item.findViewById(R.id.dupCancion);

R.id.dupCancion exists and there is a CtlDuplicado created in item’s internal array called mChildren but when I call findViewById in item it returns null…

Actualization:

I tried to access the controls inside my custom control and I can reach them in this way:

lbltxt1 = (TextView)item.findViewById(R.id.lbltxt1);
lbltxt2 = (TextView)item.findViewById(R.id.lbltxt2);
lblSubtxt1 = (TextView)item.findViewById(R.id.lblSubtxt1);

With item coming from the ‘if’…

So I can reach the components of my control but not the control itself…

The CtlDuplicado is created (I have reach to the constructor via debugger) its drawed properly but then I cannot access it via findViewById… but I can access their components via that function… Ufff…

  • 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-06T18:22:27+00:00Added an answer on June 6, 2026 at 6:22 pm

    You are not setting the actual view (probably a typo)

    item.setTag(item);
    

    should be

    item.setTag(dvh);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.
In my XML file chapters tag has more chapter tag.i need to display chapters
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
We are using XSLT to translate a RIXML file to XML. Our RIXML contains
Does anyone know how can I replace this 2 symbol below from the string

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.