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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T20:41:42+00:00 2026-06-13T20:41:42+00:00

I’ trying to develop an Android app and I’m currently stuck with something. I

  • 0

I’ trying to develop an Android app and I’m currently stuck with something.

I use a custom listview that looks as follow:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
     android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:paddingLeft="20dp"
    android:paddingRight="20dp"
    android:paddingTop="10dp"
    android:paddingBottom="10dp" >

    <TextView
        android:id="@+id/name"
        style="@style/..."/>

    <TextView
        android:id="@+id/number"
        android:layout_below="@+id/..."
        style="@style/..." />

    <TextView
        android:id="@+id/id" 
        android:layout_below="@+id/..."
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:visibility="visible" />


</RelativeLayout>

The ID’s here gets their text from my SQLite-database, where I query through my Contacts-table.

Now I want something to happen when I click on an item that is being presented in the listview. The click is registered but for now I want a Toast that just shows the number that is being passed into ID.(Primary keys for each row).

I can’t have the arrayindex +1 since I don’t order my query by id.

Here is my onItemClick:

contactList.setOnItemClickListener(new OnItemClickListener() {

        public void onItemClick(AdapterView<?> parent, View view, int position,
                long id) {

            Toast.makeText(Contacts.this,"My unique rowID should be presented here.",
                      Toast.LENGTH_SHORT).show();

        }

    });

I’m sending the unique ID’s to the textview since I believe it will make it easier to extract that info when clicking the specific item.

My base Adapter:

public class ListViewCustomAdapter extends BaseAdapter {

    public ArrayList<String> name;
    public ArrayList<String> number;
    public ArrayList<String> id;

    public Activity context;

    public LayoutInflater inflater;

    public ListViewCustomAdapter(Activity context,
            ArrayList<String> name, ArrayList<String> number, ArrayList<String> id) {
        // TODO Auto-generated constructor stub
        super();
        this.context = context;
        this.name = name;
        this.number = number;
        this.id = id;

        this.inflater = (LayoutInflater) context
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    }

    public int getCount() {
        // TODO Auto-generated method stub
        return name.size();
    }

    public Object getItem(int position) {
        // TODO Auto-generated method stub
        return null;
    }

    public long getItemId(int id) {

        return id;
    }

    public class ViewHolder {
        TextView txtViewName;
        TextView txtViewNumber;
        TextView txtViewId;

    }


    public View getView(int position, View convertview, ViewGroup parent) {
        // TODO Auto-generated method stub

        ViewHolder holder;
        if (convertview == null) {
            holder = new ViewHolder();
            convertview = inflater.inflate(R.layout.listview_row, null);

            holder.txtViewName = (TextView) convertview
                    .findViewById(R.id.name);
            holder.txtViewNumber = (TextView) convertview
                    .findViewById(R.id.number);
            holder.txtViewId = (TextView) convertview
                    .findViewById(R.id.id);

            convertview.setTag(holder);
        } else {
            holder = (ViewHolder) convertview.getTag();
        }

        holder.txtViewName.setText(name.get(position));
        holder.txtViewNumber.setText(number.get(position));
        holder.txtViewId.setText(id.get(position));

        return convertview;
    }
}

Any help would be 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-13T20:41:44+00:00Added an answer on June 13, 2026 at 8:41 pm

    For now I want a Toast that just shows the number that is being passed into ID. (Primary keys for each row).

    If you want the primary key from your database, (depending on the adapter) it should be the id parameter passed to onItemClick():

    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
        // Use id
        Toast.makeText(Contacts.this, id + "",Toast.LENGTH_SHORT).show();
    
        // Or you can find it yourself
        TextView idTV = (TextView) view.findViewById(R.id.id);
        Toast.makeText(Contacts.this, idTV.getText().toString(),Toast.LENGTH_SHORT).show();
    }
    

    Addition
    Now that you posted your adapter I see that you can adjust your getItemId() method to return data from your ArrayList<String> id to make the id parameter in onItemClick() work:

    public long getItemId(int position) {
        return Long.parseLong(id.get(position));
    }
    

    (You can even change the container type from ArrayList<String> to ArrayList<Long> if it makes sense in your context.)

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

Sidebar

Related Questions

I am trying to understand how to use SyndicationItem to display feed which is
I want use html5's new tag to play a wav file (currently only supported
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
I'm trying to create an if statement in PHP that prevents a single post
I'm parsing an XML file, the creators of it stuck in a bunch social
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has

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.