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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T07:59:42+00:00 2026-06-04T07:59:42+00:00

I take text view instance from here: TextView date = null; try { date

  • 0

I take text view instance from here:

    TextView date = null;

        try {
            date = (TextView) getLayoutInflater().inflate(
                    R.layout.some_textview, null);
        } catch (Exception e) {
            // TODO: handle exception
            e.printStackTrace();

        } 

I created my custom textview:

public class MyTextView extends TextView{

    public MyTextView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
    }

    public MyTextView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public MyTextView(Context context) {
        super(context);
    }


}

Now i want to cast those:

MyTextView my = (MyTextView)date;

I get exeption for this one:

 java.lang.ClassCastException: android.widget.TextView cannot be cast to com.myapp.name.MyTextView

So how it should be done ?

Thanks.

Edit:

If i declare date as MyTextView, still get same exception, ther is my xml of some_textview:

<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="This is a template for date text view"  
        />
  • 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-04T07:59:42+00:00Added an answer on June 4, 2026 at 7:59 am

    Is your XML-layout R.layout.some_textview resource correct?

    Don’t use

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        ...
        />
    

    You have to use your custom class in your XML:

    <com.your.package.MyTextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        ...
        />
    

    It’s very important the class-path is correct!

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

Sidebar

Related Questions

Is there some way I can take text (retrieved from a form), and email
I am customizing an open source QR Reader to take the text from a
Please take a look here: alt text http://img16.imageshack.us/img16/2810/errrp.jpg Why i got that error when
So, my app reads Data from the text view and then saves it to
I want to add a Customized UIView that will take Text input from user.
Is there a way to take text like below (if it was already in
Context: I'm trying to do is to make a program which would take text
I'm trying to take a text string, (e.g. the word testing) and calculating if
I want to create an input form that will take the input text and
Take the following example plugin: (function($) { $.fn.alertOnClick = function(text) { return this.each(function(){ $(this).click(alert(text));

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.