返回类型与AdapterView.OnItemLongClickListener.onItemLongClick不兼容(AdapterView <! - ? - >,View,int,long)

时间:2013-10-16 00:27:31

标签: android

在我的小部件中,当列表视图中的项目被长按时,我想要启动该项目(但是我目前在编码中,正常点击也会这样做但是现在我正在做长按点做某事这样我就可以在以后需要更改长按一下时进行设置。

这是我的编码:

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);
        }


    });
}
}

正如您所看到的,我基本上设置了长按以执行与正常单击相同的操作,但我得到的错误是返回类型在此行上兼容:

            public void onItemLongClick(AdapterView parent, View view,

快速修复告诉我将返回类型更改为boolean(这不对)。

我该如何解决这个问题?

1 个答案:

答案 0 :(得分:1)

  

快速修复告诉我将返回类型更改为boolean(这不对)。

为什么这不对?

According to the Docs

快速修复是正确的。为其提供booleanreturn true的返回类型。这让我们知道长时间点击是成功的。