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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T03:16:23+00:00 2026-06-13T03:16:23+00:00

I created a custom ListView. Each item in the list have one imageView and

  • 0

I created a custom ListView. Each item in the list have one imageView and two TextView.

The code is:

public class PersonalList extends ListActivity{

 public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    String[] name= new String[] { "Mary", "Frank",
            "John" };
    String[] surname = new String[] { "Ballak", "Doe",
            "Strip"" };
    setContentView(R.layout.member_list);

    MySimpleArrayAdapter adapter = new MySimpleArrayAdapter(this, name, surname);
    setListAdapter(adapter);
}

 protected void onListItemClick(ListView l, View v, int position, long id) {
    String name = (String) getListAdapter().getItem(position);
    Toast.makeText(this, "selected item: "+name, Toast.LENGTH_LONG).show();     
  }

 }

where MySimpleArrayAdapter is:

public class MySimpleArrayAdapter extends ArrayAdapter<String> {
      private final Context context;
      private final String[] name;
      private final String[] surname;

      public MySimpleArrayAdapter(Context context, String[] name, String[] surname)
      {
          super(context, R.layout.list_row, name);
          this.context = context;
          this.name= name;
          this.surname = surname;
      }

      @Override
      public View getView(int position, View convertView, ViewGroup parent) {
        LayoutInflater inflater = (LayoutInflater) context
            .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        View rowView = inflater.inflate(R.layout.rowlayout, parent, false);
        TextView nameView= (TextView) rowView.findViewById(R.id.label);
        TextView surnameView= (TextView) rowView.findViewById(R.id.label1);
        ImageView imageView = (ImageView) rowView.findViewById(R.id.icon);
        nameView.setText(name[position]);
        surnameView.setText(surname[position]);

        return rowView;
      }
  } 

Calling the following code from onListItemClick:

  Toast.makeText(this, "selected item: "+name, Toast.LENGTH_LONG).show();

I obtain for the first item a message in toast like this:

  "selected item: Mary"

What can I do in order to obtain the following result?

  "selected item: Mary Ballak"
  • 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-13T03:16:25+00:00Added an answer on June 13, 2026 at 3:16 am

    This will get you first & last names:

     protected void onListItemClick(ListView l, View v, int position, long id) {
        String name = (String) getListAdapter().getItem(position);
        Toast.makeText(this, "selected item: " + ((TextView) v.findViewById(R.id.label)).getText().toString() + " " + ((TextView) v.findViewById(R.id.label1)).getText().toString(), Toast.LENGTH_LONG).show();     
      }
    

    In addition – you can get the index from the onItemClick and get the String from the arrays (name/surname) – if you’ll save the array as members of your Activity

    Something like: String text = mName[position] + " " + msurName[position];

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

Sidebar

Related Questions

I currently have a custom listview where each item on the list contains two
I have created a custom listview using adapter. Each row of the list view
I currently have a custom listview with two rows of text in each item,
I have created a custom listview using SimpleAdapter and in each row of list
I have created a custom list view, each row has it's own custom selector,
I have 2 custom ListView Created as item layout + ArrayAdapter + My own
I have a ListView which I've created a custom view for each row. My
I created a ListView with a custom layout for each view. I have several
I have created a custom ListView with radioButton on each its rows using Custom
I have created a custom list view . In each listitem i have a

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.