gpt4 book ai didi

android - 返回类型与 AdapterView.OnItemLongClickListener.onItemLongClick(AdapterView, View, int, long) 不兼容

转载 作者:行者123 更新时间:2023-11-30 03:19:37 28 4
gpt4 key购买 nike

在我的小部件中,当 ListView 中的一个项目被长按时,我希望启动该项目(然而,在我目前的编码中,正常的点击也可以做到这一点,但现在我正在让长按做一些事情这样我就可以设置它以供以后需要更改长按的功能时使用)。

这是我的代码:

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,

快速修复告诉我将返回类型更改为 bool 值(这是不正确的)。

我该如何解决这个问题?

最佳答案

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

为什么不对?

According to the Docs

快速修复是正确的。给它一个返回类型 booleanreturn true。这让它知道长按成功。

关于android - 返回类型与 AdapterView.OnItemLongClickListener.onItemLongClick(AdapterView<?>, View, int, long) 不兼容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19393352/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com