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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T10:20:34+00:00 2026-05-27T10:20:34+00:00

I hava a listview like the following. The text in the TextView comes from

  • 0

I hava a listview like the following. The text in the TextView comes from a database.

-------------------------
TextView          Button
-------------------------

When I click on the button, I want to show the text in the TextView of this row in a Toast.

My question is the following: When I click on the button, I am showing the text of the row, which is selected by the cursor. I am not showing the text of the row where the button is. I know the problem is the mCursor variable.

I don’t know how to fix it. Has anybody an idea?

Here is my ModulCursorAdapter:

public class ModuleCursorAdapter extends ResourceCursorAdapter implements OnClickListener {
private Context mContext;
private Cursor mCursor;

    public ModuleCursorAdapter(Context context, Cursor cur) {
        super(context, R.layout.notes_row, cur);
        this.mContext = context;

    }

    @Override
    public View newView(Context context, Cursor cur, ViewGroup parent) {
        LayoutInflater li = LayoutInflater.from(context);           
        return li.inflate(R.layout.notes_row, parent, false);
    }



    @Override
    public void bindView(View view, Context context, Cursor cur) {  
        this.mCursor = cur;

        TextView tvText1 = (TextView)view.findViewById(R.id.text1);            
        Button btnButtonOFF = (Button)view.findViewById(R.id.buttonOFF);

        tvText1.setText(cur.getString(cur.getColumnIndex(NotesDbAdapter.KEY_TITLE)));

        int idRow = cur.getColumnIndex(NotesDbAdapter.KEY_ROWID);
        btnButtonOFF.setTag(cur.getInt(idRow));
        btnButtonOFF.setOnClickListener(btnButtonOFFclicked);           

    }
    @Override
    public void onClick(View view) {

    }       

    private OnClickListener btnButtonOFFclicked = new OnClickListener() {
        @Override
        public void onClick(View view) {                
            Toast.makeText(mContext,mCursor.getString(mCursor.getColumnIndex(NotesDbAdapter.KEY_TITLE)), Toast.LENGTH_LONG).show();                 
        }
    };
}

Comment

The Button in the xml-File:

<Button android:id="@+id/buttonOFF" 
        android:gravity="center"
        android:layout_height="wrap_content" 
        android:layout_width="wrap_content"
        android:layout_alignParentRight="true" 
        android:focusable="false"
        android:text="OFF" />

 <Button android:id="@+id/buttonOFF2" 
        android:gravity="center"
        android:layout_height="wrap_content" 
        android:layout_width="wrap_content"
        android:layout_alignParentRight="true" 
        android:focusable="false"
        android:onClick="btnButtonOFFclicked"
        android:text="ON" />

The OnClickMethod in the MainActivity

 public class MainActivity extends ListActivity {
 .....
 public void btnButtonOFFclicked(View view) 
  {          
     Toast.makeText(MainActivity.this,"Test", Toast.LENGTH_LONG).show();
     //Toast.makeText(mContext,mCursor.getString(mCursor.getColumnIndex(NotesDbAdapter.KEY_TITLE)), Toast.LENGTH_LONG).show();              
  }
}

MainActivity

public class MainActivity extends ListActivity {
...
private void fillData() {
    Cursor notesCursor = mDbHelper.fetchAllNotes();
    startManagingCursor(notesCursor);

   adapter = new ModuleCursorAdapter(this, notesCursor);
   setListAdapter(adapter);
}
...
}

The Notes.DbAdapter.fetchAllNotes() method

public Cursor fetchAllNotes() {
    return mDb.query(DATABASE_TABLE, new String[] {KEY_ROWID, KEY_TITLE,
            KEY_DEVICETYPE, KEY_HOMECODE, KEY_DEVICECODE}, null, null, null, null, null);
}

Thanks.

Felix

  • 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-27T10:20:34+00:00Added an answer on May 27, 2026 at 10:20 am

    Just create a private class inside you adapter like this and set listener on button in bindView method its will be like

    public void bindView(View view, Context context, Cursor cur) {  
        this.mCursor = cur;
    
        TextView tvText1 = (TextView)view.findViewById(R.id.text1);            
        Button btnButtonOFF = (Button)view.findViewById(R.id.buttonOFF);
    
        tvText1.setText(cur.getString(cur.getColumnIndex(NotesDbAdapter.KEY_TITLE)));
    
        int idRow = cur.getColumnIndex(NotesDbAdapter.KEY_ROWID);
        btnButtonOFF.setOnClickListener(new OnItemClickListener(cur.getInt(idRow)));           
    
    }
    
    private class OnItemClickListener implements OnClickListener {
        private int position;
    
    
        public OnItemClickListener(int position) {
            super();
            this.position = position;
        }
    
    
        @Override
        public void onClick(View v) {
            // position is an id.
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i hava a c++ method(for java,jni) like follow,when i repeat call this from java
I hava text file full of values like this: The first line is a
I hava a binary file like this : offset | size/type | Description -------+-----------+-----------------------------------------------------------
I hava a java program, a section of it is compute intensive, like this
I hava a class like this: public class tbl050701_1391_Fields { public static readonly string
I hava a data structure that looks like this: (def conf { :devices [{:alias
i hava a set of following tables customer(cus_id,cus_name); jointAccount(cus_id,acc_number,relationship); account(acc_number,cus_id) now i want to
I hava a field in my database containing street and housenumber. I want to
I hava a stored procedure named PROC_fetchTableInfo (simple select from sys.tables) in a database
I hava set up AJAX script that when you click the button it calls

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.