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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T02:54:48+00:00 2026-06-01T02:54:48+00:00

1.) My main.xml contains : <ListView android:id="@+id/lsym" android:layout_width="wrap_content" android:layout_height="wrap_content"/> 2.) After populating the list,

  • 0

1.) My main.xml contains :

<ListView
        android:id="@+id/lsym"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"/>

2.) After populating the list, I’m assigning an adapter to it as follows :

lsym.Adapter=new SymbolAdapter(this,result);

where result is a DataTable.

3.) Within SymbolAdapter, I have used :

convertView = inflater.Inflate(Resource.Layout.list_symbol, null);

4.) list_symbol.xml contains :

<RelativeLayout android:id="@+id/symbolLayout" 
    android:layout_height="wrap_content" 
    android:layout_width="wrap_content">

    <TextView 
        android:id="@+id/tvsym" 
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />
</RelativeLayout>

5.) And finally, for list item click, I’m using following code snippet:

   lsym.ItemClick+= SearchItem_Click;

&

   private void SearchItem_Click(object sender, ItemEventArgs e)
        {
            string  company=((TextView)e.View).Text;
            Toast.MakeText(this, "Selected="+company,ToastLength.Short).Show();
        }

as specified here.

But when I click a list item, it is giving me following error :

System.InvalidCastException: Cannot cast from source type to destination type.
SearchItem_Click (object,Android.Widget.ItemEventArgs)

at ((TextView)e.View).Text.

ANY IDEA WHY THIS IS HAPPENING?
I know I have put up lot of code but as I’m absolute beginner to mono for android, so any help appreciated.

  • 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-01T02:54:50+00:00Added an answer on June 1, 2026 at 2:54 am

    e.View is RelativeLayout so casting it to TextView will not work …
    instead of this you should call FindViewById(Resource.Id.tvsym) on that view ( not just plain since it will be called on Activity)

    code should looks like:

    TextView rowText = (TextView)e.View.FindViewById(Resource.Id.tvsym);

    EDIT: or in Mono you can use:

    TextView rowText = e.View.FindViewById<TextView>(Resource.Id.tvsym);

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

Sidebar

Related Questions

main.xml <?xml version=1.0 encoding=utf-8?> <LinearLayout xmlns:android=http://schemas.android.com/apk/res/android android:id=@+id/root android:layout_width=match_parent android:layout_height=wrap_content android:orientation=vertical > <LinearLayout android:id=@+id/horizontal android:layout_width=fill_parent
I have an Activity whose layout is in the file main.xml that contains a
My main.xml looks like this: <?xml version=1.0 encoding=utf-8?> <LinearLayout xmlns:android=http://schemas.android.com/apk/res/android android:orientation=vertical android:layout_width=fill_parent android:layout_height=fill_parent >
I'm populating a ListView which contains an ImageView and a TextView. It doesn't crash,
My main.xml layout simply contains a button and a LinearLayout content_area , which shows
I'm trying to create a widget for Android. It contains such files: res/xml/widgetinfo.xml: <?xml
Hi I have an application which after login, loads a main activity which contains
here is my layuout main.xml ; <?xml version=1.0 encoding=utf-8?> <LinearLayout xmlns:android=http://schemas.android.com/apk/res/android android:orientation=vertical android:layout_width=fill_parent android:layout_height=fill_parent>
I have a main menu screen with a simple ListView that contains links to
My main.xml has 2 edit text for the user to insert values. And my

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.