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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T21:01:42+00:00 2026-05-24T21:01:42+00:00

I am trying to make a custom view using XML then retrieve its properties

  • 0

I am trying to make a custom view using XML then retrieve its properties and edit them. This custom view is added into the test2 view several times with different id’s for each. I have tried to retrieve the id for one of these custom views (player_1) then get the TextView (player_name), and edits its properties and no other views like the player_2 id view.

But I am not sure that this is this even possible? It renders fine, but I get an error every time I try to do this in code. I’m really not sure how to approach this, I can’t seem to get inflate to work either to test that instead. Any ideaS?

Thanks!

Game.java

setContentView(R.layout.test2);

View player1 = (View) findViewById(R.id.player_1);

TextView player1Name = (TextView) player1.findViewById(R.id.player_name);

player1Name.setText("John");

test2.xml

<include
    layout="@layout/player_view"
    android:id="@+id/player_1"
/>
<include
    layout="@layout/player_view"
    android:id="@+id/player_2"
/>

player_view.xml

<?xml version="1.0" encoding="utf-8"?>
<merge
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:player="http://schemas.android.com/apk/res/com.example.android.merge">
<LinearLayout
android:id="@+id/top_view"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
>
        <TextView
        android:id="@+id/player_name"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="TextView"
        >
        </TextView>
   </LinearLayout>
</merge>

This is a cut down version of player_view.xml, I can post more if needed.

Also I have not worked out if it even prints the error message for this in eclipse, it goes into debug mode and does not explain any further what the issue is.

  • 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-24T21:01:43+00:00Added an answer on May 24, 2026 at 9:01 pm

    Your player_view.xml has unknown type, so the include is confused what kind of View is it. Try to do the next:
    Use or create new PlayerView class, mergeable with player_view.xml.

    Edit test2.xml to:

    <PlayerView
        android:id="@+id/player_1"
    />
    <PlayerView
        android:id="@+id/player_2"
    />
    

    then inflate it in your code as following:

    setContentView(R.layout.test2);
    
    PlayerView player1 = (PlayerView) findViewById(R.id.player_1);
    LayoutInflater inflate = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    inflate.inflate(R.layout.player_view, player1);
    

    Do the same for player2.

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

Sidebar

Related Questions

I'm trying to make a custom view in Django admin. I'm reading from this
I'm trying to make a custom dialog to show a view in this dialog.
I'm trying to make a custom Callout view for AnnotationView. I had seen this
I'm trying to make a custom Callout view for AnnotationView. I had seen this
I'm trying to make a custom infowindow. Version = 2. I have added my
I'm trying to make scrollable RelativeLayout, that contains some custom Views. This is the
I'm trying to create a custom Android compound view, here is the code: <?xml
Im trying to make a custom view that will have a dynamic number of
Trying to make a custom :confirm message for a rails form that returns data
I am writing a custom session handler in PHP and trying to make 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.