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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T17:10:23+00:00 2026-06-02T17:10:23+00:00

I have a ListView which contains some texts and pic for each item (it’s

  • 0

I have a ListView which contains some texts and pic for each item (it’s the row actually). When I click on one of them, it triggers a listener and open a dialog.

The content shown in Dialog is retrieved from the item in ListView. I tried several ways but the parameters passed in are all null pointer.

Say, I’m trying to get the value of hotelName which is in the layout of listview. The id of that TextView is R.id.nameTV

final Context context = this;

public void onCreate(Bundle blabla){

    final ListView listView = getListView();
    listView.setTextFilterEnabled(true);

    listView.setOnItemClickListener(new OnItemClickListener() {
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {

            final Dialog dialog = new Dialog(context);

            // this is the TextView in Dialog to hold the content from ListView
            TextView dHotelTV = (TextView)findViewById(R.id.hotelNameTV);

            CharSequence hotelName;
            /* 
                The way I tried:
                hotelName = context.getText(R.id.nameTV);
                hotelName = view.findViewById(R.id.nameTV); 

            */

            dialog.setTitle("EasyTrip");
            dialog.setContentView(R.layout.dialog);
            dHotelTV.setText(hotelName)

     }
}

The hotelName from these methods are all null pointer. It drives me crazy.

What am I doing wrong?

  • 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-02T17:10:25+00:00Added an answer on June 2, 2026 at 5:10 pm

    Pull it from the textView:

    hotelName = ((TextView) view.findViewById(R.id.my_important_textview)).getText();
    

    Also, if dHotelTV is an element in the dialog, you’re not going to find it using findViewById in the activity, and you’ll get another NullPointerException:

     dialog.setContentView(R.layout.dialog);
     TextView dHotelTV = (TextView)dialog.findViewById(R.id.hotelNameTV);
    

    Note that findViewById() is scoped – It only looks for children. So if you have a listView where each Item is defined by this layout:

    <LinearLayout
      ...
    >
      <TextView
        ...
        android:id="@+id/my_important_textView" />
      <TextView
        ...
        android:id="@+id/other_textview" />
    </ LinearLayout>
    

    then if you call findViewById() on that item:

    ((TextView) view.findViewById(R.id.my_important_textview)).getText();
    

    The call is scoped to the item you clicked on.

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

Sidebar

Related Questions

I have a ListView in which each item has a complex layout that contains,
I have a ListView with some text, each row contains different length text and
I have a ListView which contains custom rows. This custom row has following UI
Hallo all, I have a ListView, which contains an EditText in each of it's
I have a ListView which contains EMPLOYEE_NAME from a DB table EMPLOYEE. Some employees
I have one custom ListView which contains one ImageView and one TextView, and I
I have a page which contains a listview alone. Upon clicking a row in
I have an object submission which contains some informations which I would like to
I have a listview where each list item can contain 1 or more clickable
I have a listview NoteList which contains a method doListRefresh() to select list contents

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.