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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T17:26:34+00:00 2026-06-15T17:26:34+00:00

I did a query in a database and return it inside a list that

  • 0

I did a query in a database and return it inside a list that i put on a custom adapter and then i put in a listview.
Works fine until i use the onItemClikListener. I want to get the column “_id” from the query and i don’t know how to do it (i want to pass this id as parameter for another activity).
I tried getItemId from my custom adapter but it returns the position on the list, not the column “_id”.
Ex.: my query select * where name = x; return rows with id 1 and 3…but the getItemId make it position 1=”_id1″ and 2=”_id3″…and when i pass it no another activity the query returns the rows with the “_id” 1 and 2;

//Here i get the item position and pass to another activity
listagem.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> arg0, View arg1,int position, long id) {    
    String Column_id = String.valueOf(adapter.getItemId(position));
    Intent mostraLetra = new Intent(musica.this.getActivity(), ExibeMusica.class);
    mostraLetra.putExtra("id", Column_id);
    startActivity(mostraLetra);
    }
});

//Here i pass the Id when i click on a item on the list
public String[] exibeMusica(String idMusica){
    String r = idMusica;
    String[] resultado = {};
    Cursor resul = bancodados.query(Tabela_musica, new String[] {"_id", "Musica","Cantor","letra_musica","cat_oracao","cat_missa"}, "_Id = " +r+"", null, null, null, null, null);
    resul.moveToFirst();
    resultado[0] = String.valueOf(resul.getString(resul.getColumnIndex("_id")));
    resultado[1] = resul.getString(resul.getColumnIndex("Musica"));
    resultado[2] = resul.getString(resul.getColumnIndex("Cantor"));
    resultado[3] = resul.getString(resul.getColumnIndex("letra_musica"));
    resultado[4] = resul.getString(resul.getColumnIndex("cat_oracao"));
    resultado[5] = resul.getString(resul.getColumnIndex("cat_missa"));
    resul.close();
    return resultado;
}

//This is my custom adapter
public class CustomAdapter extends BaseAdapter{

LayoutInflater inflater;
List<musica.ItemLista> itens;

public CustomAdapter(Activity a, List<musica.ItemLista> itens) {
    super();    
    this.itens = itens;
    this.inflater = (LayoutInflater)a.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}

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

public Object getItem(int position) {

    return position;
}

public long getItemId(int position) {
    return position;
}

public View getView(int position, View convertView, ViewGroup parent) {

    musica.ItemLista item = itens.get(position);
    View vi = convertView;

    if(convertView==null){
        vi = inflater.inflate(R.layout.linha_listview, null);
        TextView id = (TextView)vi.findViewById(R.linhaLista.id);
        TextView musica = (TextView)vi.findViewById(R.linhaLista.musica);
        TextView artista = (TextView)vi.findViewById(R.linhaLista.cantor);
        ImageView oracao = (ImageView)vi.findViewById(R.linhaLista.cat_oracao);
        ImageView missa = (ImageView)vi.findViewById(R.linhaLista.cat_missa);
        id.setText(String.valueOf(item.id));
        musica.setText(item.musica);
        artista.setText(item.cantor);
        String imgOra = item.oracao;
        String imgMissa = item.missa;

        if (imgOra.equals(null)) {
            oracao.setImageResource(R.drawable.blank);
        }else if(imgOra.equals("louvor")) {
            oracao.setImageResource(R.drawable.louvor);
        }else if(imgOra.equals("adoracao")) {
            oracao.setImageResource(R.drawable.adoracao);
        }

        if (imgMissa.equals(null)) {
            missa.setImageResource(R.drawable.blank);
        }else if(imgOra.equals("louvor")) {
            missa.setImageResource(R.drawable.louvor);
        }else if(imgOra.equals("adoracao")) {
            missa.setImageResource(R.drawable.adoracao);
        }
    }return vi;
    }
}

Anyone can help me to get the correct “_id” ?

  • 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-15T17:26:34+00:00Added an answer on June 15, 2026 at 5:26 pm

    Set tag to the row view in getView of the adapter like this

        .........
        }
        vi.setTag(String.valueOf(item.id))
        return vi;
        .........
    

    and then

    public void onItemClick(AdapterView<?> arg0, View arg1,int position, long id) {    
    String Column_id = (String) arg1.getTag();
    ......
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I was successful in writing the query that lists salesmen that did sell to
Here's a SQL query that I slightly scrubbed (just the column/table/database names). I kept
I Want To List Tables Of a database with sp_msforeachtable.i did it well in
I have an application that uses hibernate. I did the following: Used List to
I'm reading a dBase database and then sending that table to a SQL Server
I get a android.database.sqlite.DatabaseObjectNotClosedException: Application did not close the cursor or database object that
I am attempting to write a MySQL query that will return element whose details
I keep getting an Notice: Undefined index: did error with this query, and I'm
I'm pretty sure I did this right, but my query has been running for
Why would the database be hit to find a record that is already represented

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.