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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T20:28:59+00:00 2026-06-10T20:28:59+00:00

I have already asked this, but didn’t get an solution that works and I

  • 0

I have already asked this, but didn’t get an solution that works and I have since amedned the code.

Can anyone help me and advise why my Long Click function is not working please?:

public class InspectionActivity extends ListActivity {
private Button newInspection;
private static final int ACTIVITY_CREATE=0;

private RMDbAdapter rmDbHelper;
//private AlertDialog longClickOptionsDialog;
private AlertDialog clickOptionsDialog;


@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_inspection);
    setUpViews();
    rmDbHelper = new RMDbAdapter(this);
    rmDbHelper.open();

    // Get a Cursor for the list items
    Cursor listCursor = rmDbHelper.fetchAllInspections();
    startManagingCursor(listCursor);           

    // set the custom list adapter     
    setListAdapter(new MyListAdapter(this, listCursor));

}

private void setUpViews() {
    newInspection = (Button)findViewById(R.id.new_inspection);
    newInspection.setOnClickListener(new View.OnClickListener() {                       
        public void onClick(View v) {
            createInspection();
        }
    }); 

}

// In your ListActivity class, create a new inner class that extends ResourceCursorAdapter. 
//This inner class is the custom CursorAdapter we will use to manage how data is bound to a list item:

private class MyListAdapter extends ResourceCursorAdapter { 

    public MyListAdapter(Context context, Cursor cursor) { 
        super(context, R.layout.inspection_row, cursor);

    } 

    @Override
    public void bindView(View view, Context context, Cursor cursor) { 
        TextView title = (TextView) view.findViewById(R.id.inspection_row_item_main_title);
        title.setText(cursor.getString(                            
                cursor.getColumnIndex(RMDbAdapter.INSPECTION_REF)));

        TextView description = (TextView) view.findViewById(R.id.inspection_row_item_description);        

        String companyName = RMUtilities.notEmpty(cursor.getString(cursor.getColumnIndex(
                        RMDbAdapter.INSPECTION_COMPANY)), "Company unknown");
        String inspectionDate = RMUtilities.notEmpty(cursor.getString(cursor.getColumnIndex(
                        RMDbAdapter.INSPECTION_DATE)), "date unknown");
        description.setText("(" + companyName + ", " + inspectionDate + ")");   
    } 
}


private void createInspection() {
    Intent i = new Intent(this, InspectionEdit.class);
    startActivityForResult(i, ACTIVITY_CREATE);
}
protected void onListItemClick(ListView l, View v, final int pos, final long id){


    Cursor cursor = (Cursor) rmDbHelper.fetchInspection(id);

    String inspectionRef = RMUtilities.notEmpty(cursor.getString(cursor.getColumnIndex( 
            RMDbAdapter.INSPECTION_REF)), "Reference unknown"); 
    String companyName = RMUtilities.notEmpty(cursor.getString(cursor.getColumnIndex( 
            RMDbAdapter.INSPECTION_COMPANY)), "company unknown"); 
    final String inspectionDialogueText = "(" + inspectionRef + ", " + companyName + ")"; 

    super.onListItemClick(l, v, pos, id);
    clickOptionsDialog = new AlertDialog.Builder(InspectionActivity.this)
    .setTitle(inspectionDialogueText)
    .setMessage(R.string.general_text_select_option)
    .setPositiveButton(R.string.general_button_open, new AlertDialog.OnClickListener(){
        public void onClick(DialogInterface dialog, int which) {
            Intent i = new Intent(InspectionActivity.this, AreaActivity.class);
            i.putExtra("intentID", id);
            startActivityForResult(i, ACTIVITY_CREATE);
            }
        })
    .setNeutralButton(R.string.general_button_edit, new AlertDialog.OnClickListener(){
        public void onClick(DialogInterface dialog, int which){
            Intent i = new Intent(InspectionActivity.this, InspectionEdit.class);
            i.putExtra("intentID", id);
            startActivityForResult(i, ACTIVITY_CREATE);
            }
        })

    .setNegativeButton(android.R.string.cancel, new AlertDialog.OnClickListener(){
        public void onClick(DialogInterface dialog, int which){
            clickOptionsDialog.cancel();
            }
        })
    .create();
    clickOptionsDialog.show();

}

protected void onListItemLongClick(ListView l, View v, final int pos, final long id){

    Cursor cursor = (Cursor) rmDbHelper.fetchInspection(id);

    String inspectionRef = RMUtilities.notEmpty(cursor.getString(cursor.getColumnIndex( 
            RMDbAdapter.INSPECTION_REF)), "Reference unknown"); 
    String companyName = RMUtilities.notEmpty(cursor.getString(cursor.getColumnIndex( 
            RMDbAdapter.INSPECTION_COMPANY)), "company unknown"); 
    final String inspectionDialogueText = "(" + inspectionRef + ", " + companyName + ")"; 

    clickOptionsDialog = new AlertDialog.Builder(InspectionActivity.this)
    .setTitle(inspectionDialogueText)
    .setMessage(R.string.general_text_select_option)
    .setPositiveButton(R.string.general_button_open, new AlertDialog.OnClickListener(){
        public void onClick(DialogInterface dialog, int which) {
            Intent i = new Intent(InspectionActivity.this, AreaActivity.class);
            i.putExtra("intentID", id);
            startActivityForResult(i, ACTIVITY_CREATE);
            }
        })
    .setNeutralButton(R.string.general_button_edit, new AlertDialog.OnClickListener(){
        public void onClick(DialogInterface dialog, int which){
            Intent i = new Intent(InspectionActivity.this, InspectionEdit.class);
            i.putExtra("intentID", id);
            startActivityForResult(i, ACTIVITY_CREATE);
            }
        })

    .setNegativeButton(android.R.string.cancel, new AlertDialog.OnClickListener(){
        public void onClick(DialogInterface dialog, int which){
            clickOptionsDialog.cancel();
            }
        })
    .create();
    clickOptionsDialog.show();
} 

Your help will be much appreciated.

Thanks,

Dave

  • 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-10T20:29:00+00:00Added an answer on June 10, 2026 at 8:29 pm

    You can not override the onListItemLongClick because its not a member of ListActivity

    http://developer.android.com/reference/android/app/ListActivity.html

    You have to set the OnItemLongClickListener as followed:

    ListView lv = getListView();
    lv.setOnItemLongClickListener(new OnItemLongClickListener() {
        @Override
        public boolean onItemLongClick(AdapterView<?> arg0, View arg1,int row, long arg3) {
            // your code
        }
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Apologies if this was already asked but, I have had a look and can't
I have already asked this question on SuperUser but it was suggested there that
I know that this question was asked earlier but the OP didn't get any
I guess this question that would have already been asked here. I searched but
I think I already asked this but the solution didn't really made sense. Anyway,
I have already asked this, but can't find reason of my problem( My dropkick
This may have been already asked but I can't seem to find this specific
I have gone through many questions already asked about this problem but i didn't
I'm sure others have already asked this, but is it possible to insert an
I am sorry I have already asked this question on Superuser, but nobody answers

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.