首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >返回类型与AdapterView.OnItemLongClickListener.onItemLongClick(AdapterView<?>,视图、int、long不兼容)

返回类型与AdapterView.OnItemLongClickListener.onItemLongClick(AdapterView<?>,视图、int、long不兼容)
EN

Stack Overflow用户
提问于 2013-10-16 00:27:30
回答 1查看 674关注 0票数 1

在我的小部件中,当列表视图中的项被长按时,我希望启动该项目(然而,在我目前的编码中,普通的单击也会这样做,但现在我正在做一些长点击,以便在以后需要更改长单击所做的操作时设置它)。

这是我的编码:

代码语言:javascript
复制
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);
        }


    });
}
}

如您所见,我基本上是在设置长单击以执行与普通单击相同的操作,但我得到的错误是返回类型在这一行上是兼容的:

代码语言:javascript
复制
            public void onItemLongClick(AdapterView parent, View view,

快速修复告诉我将返回类型更改为布尔值(这是不对的)。

我怎么才能解决这个问题?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-10-16 00:59:53

快速修复告诉我将返回类型更改为布尔值(这是不对的)。

为什么这样做不对?

根据医生的说法

快速修复是正确的。给它一个返回类型的booleanreturn true。这让我们知道长时间的点击是成功的。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/19393352

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档