user1628978
user1628978

Reputation: 501

The return type is incompatible with AdapterView.OnItemLongClickListener.onItemLongClick(AdapterView<?>, View, int, long)

In my widget, when an item in a listview is long-pressed, I want that item to be launched (in my coding currently however, a normal click does this also but for right now I am making the long click do something so that I have it set up for later when I need to change what the long click does).

Here is my coding:

package com.example.awesomefilebuilderwidget;

import android.app.Activity;
import android.content.pm.ApplicationInfo;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemLongClickListener;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.AdapterView.OnItemClickListener;

public class Drag_and_Drop_App extends Activity {
private ListView mListAppInfo;
// Search EditText
EditText inputSearch;


@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    // set layout for the main screen
    setContentView(R.layout.drag_and_drop_app);
    // create new adapter
    AppInfoAdapter adapter = new AppInfoAdapter(this, Utilities.getInstalledApplication(this), getPackageManager());
    // set adapter to list view
    mListAppInfo.setAdapter(adapter);
    // search bar
    inputSearch = (EditText) findViewById(R.id.inputSearch);

    inputSearch.addTextChangedListener(new TextWatcher() {

        @Override
        public void onTextChanged(CharSequence cs, int arg1, int arg2, int arg3) {
            // When user changed the Text
            Drag_and_Drop_App.this.adapter.getFilter().filter(cs);  

        }

        @Override
        public void beforeTextChanged(CharSequence arg0, int arg1, int arg2,
                int arg3) {
            // TODO Auto-generated method stub

        }

        @Override
        public void afterTextChanged(Editable arg0) {
            // TODO Auto-generated method stub                          
        }
        });
     // load list application
    mListAppInfo = (ListView)findViewById(R.id.lvApps);

    // implement event when an item on list view is selected
    mListAppInfo.setOnItemClickListener(new OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView parent, View view, int pos, long id) {
            // get the list adapter
            AppInfoAdapter appInfoAdapter = (AppInfoAdapter)parent.getAdapter();
            // get selected item on the list
            ApplicationInfo appInfo = (ApplicationInfo)appInfoAdapter.getItem(pos);
            // launch the selected application
            Utilities.launchApp(parent.getContext(), getPackageManager(), appInfo.packageName);
        }

    });

    // implement event when an item on list view is selected via long-click for drag and drop
    mListAppInfo.setOnItemLongClickListener(new OnItemLongClickListener(){

        @Override
        public void onItemLongClick(AdapterView parent, View view,
                int pos, long id) {
            // TODO Auto-generated method stub
            // get the list adapter
            AppInfoAdapter appInfoAdapter = (AppInfoAdapter)parent.getAdapter();
            // get selected item on the list
            ApplicationInfo appInfo = (ApplicationInfo)appInfoAdapter.getItem(pos);
            // launch the selected application
            Utilities.launchApp(parent.getContext(), getPackageManager(), appInfo.packageName);
        }


    });
}
}

As you can see, I am basically setting up the long click to do the same thing as a normal click but I get the error that the return type is compatible on this line:

            public void onItemLongClick(AdapterView parent, View view,

Quick fix tells me to change the return type to boolean (which isn't right).

How can I fix this?

Upvotes: 1

Views: 692

Answers (1)

codeMagic
codeMagic

Reputation: 44571

Quick fix tells me to change the return type to boolean (which isn't right).

Why isn't this right?

According to the Docs

The quick fix is correct. Give it a return type of boolean and return true. This let's it know that the long click was successful.

Upvotes: 1

Related Questions