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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T03:21:40+00:00 2026-05-22T03:21:40+00:00

I am having a problem, I am trying to get the text of a

  • 0

I am having a problem, I am trying to get the text of a listView Item using onItemClick method of the OnItemClickListener interface. The problem is the layout of the simpleCursorAdaptor has 3 TextViews, how do I get the text of only one of those TextViews? I am getting an ClassCastException. How Can I extract the contents of all the 3 textViews in the layout. Here is my code

package com.messageHider;

import android.app.Activity;
import android.content.ContentResolver;
import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;
import android.widget.SimpleCursorAdapter;
import android.widget.TextView;
import android.widget.Toast;

public class sms extends Activity implements OnItemClickListener
{
ListView listViewSMS;
Uri smsUri=Uri.parse("content://sms/inbox");
Cursor cursor;
SimpleCursorAdapter adapter;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.sms);
    listViewSMS=(ListView)findViewById(R.id.listViewSMS);
    listViewSMS.setOnItemClickListener(this);
}
@Override
protected void onStart() {
    super.onStart();
    getsms();
}
private void getsms()
{
    cursor=getContentResolver().query(smsUri,null, null, null, null);
    String[]from={"person","body","date"};
    int[]to={R.id.textViewPerson,R.id.textViewBody,R.id.textViewDate};
    adapter=new SimpleCursorAdapter(this,R.layout.smslist, cursor, from, to);
    listViewSMS.setAdapter(adapter);
}
@Override
public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
    Toast.makeText(getApplicationContext(),((TextView) v).getText(), Toast.LENGTH_LONG).show();
    }
}

Here is the layout for the adaptor:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="match_parent"
  android:layout_height="match_parent" android:orientation="vertical">
    <LinearLayout android:layout_height="wrap_content" android:id="@+id/linearLayout1" android:layout_width="match_parent">
        <TextView android:text="TextView" android:layout_height="wrap_content" android:padding="5dp" android:layout_width="wrap_content" android:id="@+id/textViewPerson"></TextView>
        <TextView android:text="TextView" android:layout_height="wrap_content" android:layout_width="fill_parent"  android:id="@+id/textViewDate" android:gravity="right" android:paddingRight="5dp"></TextView>
    </LinearLayout>
    <TextView android:text="TextView" android:id="@+id/textViewBody" android:layout_height="wrap_content" android:height="60dp" android:padding="5dp" android:layout_width="fill_parent"></TextView>
</LinearLayout>

I will appreciate the help.

  • 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-22T03:21:41+00:00Added an answer on May 22, 2026 at 3:21 am

    You receive the whole LinearLayout as the parameter v.
    You should try v.findViewById() and then use this textview.

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

Sidebar

Related Questions

I'm having a problem using the java.text.MessageFormat object. I'm trying to create SQL insert
I am trying to get started with PEAR's HTML_QuickForm but I'm having a problem.
I am having a bit of a problem, I am trying to get a
I'm having an annoying problem trying to get an html page with a google
I'm having a problem with JQGrid using ASP.NET MVC. I'm trying to follow this
My friend has this embarassing problem. He's trying to get the most basic of
Hi everyone I am having a problem trying to get this to work. Basically
I'm having a problem loading a PHP file using .get (even used .load) with
I'm trying to get plaxo's Address Book Access working. I'm having the following problem:
I'm having a quite specific CSS problem. I'm trying to get a paragraph of

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.