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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T18:55:49+00:00 2026-05-26T18:55:49+00:00

I have this SimpleCursorAdapter for my ListView, the view is set from NewView. I’m

  • 0

I have this SimpleCursorAdapter for my ListView, the view is set from NewView. I’m trying to make that everytime the row is clicked, it leads to a new activity carrying the row’s attribute to the new activity.

Normally I do this with OnItemClickListener, but since I’m using SimpleCursorAdapter and NewView, the only option I got to make the row clickable is by using OnClickListener.

But I have difficulty in implementing the method I used to have on OnItemClickListener to OnClickListener. Especially I have no idea how I deal with ‘id’ and ‘position’ on OnCLick.

Here’s the OnItemClickListener I used to have:

protected void onItemClick(AdapterView<?> l, View v, int position, long id) {
            Intent listIntent = new Intent(ProjectsList.this, DetailsActivity.class);
            listIntent.putExtra("spendino.de.ProjectDetail.position",position);
            listIntent.setData(Uri.withAppendedPath(Uri.withAppendedPath(
                    Provider.CONTENT_URI, Database.Project.NAME), Long
                    .toString(id)));
            startActivity(listIntent);}

And here’s my SimpleCursorAdapter Class:

class MySimpleCursorAdapter extends SimpleCursorAdapter {
            Context context=null;
            ImageLoader loader = null;
            private LayoutInflater mInflater = null;
            private int mProjectNameIndex = -1;
            private int mOrgNameIndex = -1;
            private int mDescIndex = -1;
            private int mDonationIndex = -1;
            private int mSmallImageIndex = -1;
            private int mKeywordIndex = -1;
            private int mPriceIndex = -1;
            private int mShortcodeIndex = -1;



            public MySimpleCursorAdapter(Context context, int layout, Cursor c,
                    String[] from, int[] to) {
                super(context, layout, c, from, to);
                loader = new ImageLoader(context);
                this.context = context;

                mInflater = getLayoutInflater();    
                mProjectNameIndex = c.getColumnIndexOrThrow(Database.Project.C_PROJECTTITLE);
                mOrgNameIndex = c.getColumnIndexOrThrow(Database.Project.C_ORGANIZATIONTITLE);
                mDescIndex = c.getColumnIndexOrThrow(Database.Project.C_PROJECTDESCRIPTION);
                mDonationIndex = c.getColumnIndexOrThrow(Database.Project.C_DONATIONAMOUNT);
                mSmallImageIndex = c.getColumnIndexOrThrow(Database.Project.C_SMALLIMAGE);
                mKeywordIndex = c.getColumnIndexOrThrow(Database.Project.C_KEYWORD);
                mPriceIndex = c.getColumnIndexOrThrow(Database.Project.C_PRICE);
                mShortcodeIndex = c.getColumnIndexOrThrow(Database.Project.C_SHORTCODE);

            }

            @Override
            public View newView(Context context, Cursor cursor, ViewGroup parent) {
                View convertView = mInflater.inflate(R.layout.listitems, null);
                convertView.setClickable(true);
                convertView.setFocusable(true);
                convertView.setBackgroundResource(android.R.drawable.menuitem_background);

                convertView.setOnClickListener(new OnClickListener() {
                     public void onClick(View view) {


                } 
                      });   




                return convertView;
            }

Here’s the line which tells that everytime the row is clicked it has to go to a new activity carrying its attributes:

convertView.setOnClickListener(new OnClickListener() {
                     public void onClick(View view) {


                } 
                      });   

I’m a newbie in this one, I really need a solution to deal with the difficulty I’m facing

  • 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-26T18:55:49+00:00Added an answer on May 26, 2026 at 6:55 pm

    I am not aware of any issues with using onItemClickListener on a ListView that uses a SimpleCursorAdapter.

    newView effectively does the same thing as another adapter’s getView as far as the ListView is concerned – they both give Views that are used as rows in the list, and the ListView provides the onItemClickListener interface independently of the adapter.

    However, manually setting the View to be click-able may intercept the touch event intended for onItemClick so try your old onItemClickListener and don’t call

    convertView.setClickable(true);
    

    UPDATED:
    Change the line in your newView method to:

      convertView.setOnClickListener(new ClickListener(context, cursor.getString(mProjectNameIndex), convertView.getId()));
    

    which uses this class:

    class ClickListener implements OnClickListener {
        Intent listIntent;
    
        public ClickListener(Context c, String name, long id) {
            listIntent = new Intent(c, DetailsActivity.class);
            listIntent.putExtra("spendino.de.ProjectDetail.name", name);
            listIntent.setData(Uri.withAppendedPath(Uri.withAppendedPath(
                    Provider.CONTENT_URI, Database.Project.NAME), Long
                    .toString(id)));
        }
    
        public void onClick(View v) {
            v.getContext().startActivity(listIntent);
        }
    }
    

    Also override bindView in your adapter (this is because Views created in newView can be reused).

    @Override
    public void bindView (View view, Context context, Cursor cursor) {
        if(view != null) {
            view.setOnClickListener(new ClickListener(context, cursor.getString(mProjectNameIndex), view.getId()));
        }
        super.bindView(view, context, cursor);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a listview which is populated by a SimpleCursorAdapter that is binding data
I have a ListView (set to CHOICE_MODE_SINGLE) I have a SimpleCursorAdapter who fill my
I have a ListView that is fed by an SQLiteDB. On each row returned,
I have a ListView backed by SimpleCursorAdapter and custom ViewBinder. I want to make
I am trying to make a program that has 2 views. The first view
I have a custom listview row that contains a number of textView components. Instead
I have a listView of contacts that I got from the Android ContactManager sample.
I have this code in jQuery, that I want to reimplement with the prototype
I have this RewriteRule that works too well :-) RewriteRule ^([^/]*)/$ /script.html?id=$1 [L] The
I have this line in a useful Bash script that I haven't managed to

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.