gpt4 book ai didi

java - 无法在扩展 ArrayAdapter 的类中解析方法 super

转载 作者:搜寻专家 更新时间:2023-11-01 08:50:04 24 4
gpt4 key购买 nike

在我创建的 Android 应用程序中,我有一个可滚动的选项卡,在其中一个 fragment 中,我试图显示所有用户下载的应用程序。

我正在尝试使用一个 fragment 来实现它

http://javatechig.com/android/how-to-get-list-of-installed-apps-in-android

我的应用程序类扩展了 Fragment。该类用于初始化和列出已安装的应用程序。因为从 PackageManage 获取应用程序详细信息列表是一项长期运行的任务。

此外,该类使用扩展 ArrayAdapter 的 ApplicationAdapter 类。

我的 ApplicationAdapter 类收到此错误。

enter image description here

我想弄清楚为什么 super 无法解析以及如何修复它。不应该一开始就调用吗?

这是我的 ApplicationAdapter 类的 java 代码:

package com.javatechig.listapps;

import android.content.Context;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.spicycurryman.getdisciplined10.app.InstalledAppActivity;
import com.spicycurryman.getdisciplined10.app.R;

import java.util.List;







public class ApplicationAdapter extends ArrayAdapter<ApplicationInfo> {
private List<ApplicationInfo> appsList = null;
private InstalledAppActivity context;
private PackageManager packageManager;

public ApplicationAdapter(InstalledAppActivity context, int textViewResourceId,
List<ApplicationInfo> appsList) {
super(context, textViewResourceId, appsList);
this.context = context;
this.appsList = appsList;
packageManager = context.getActivity().getPackageManager();
}

@Override
public int getCount() {
return ((null != appsList) ? appsList.size() : 0);
}

@Override
public ApplicationInfo getItem(int position) {
return ((null != appsList) ? appsList.get(position) : null);
}

@Override
public long getItemId(int position) {
return position;
}

@Override
public View getView(int position, View convertView, ViewGroup parent) {
View view = convertView;
if (null == view) {
LayoutInflater layoutInflater = (LayoutInflater) context.getActivity().
getSystemService(Context.LAYOUT_INFLATER_SERVICE);
view = layoutInflater.inflate(R.layout.snippet_list_row, null);
}

ApplicationInfo data = appsList.get(position);
if (null != data) {
TextView appName = (TextView) view.findViewById(R.id.app_name);
TextView packageName = (TextView) view.findViewById(R.id.app_package);
ImageView iconview = (ImageView) view.findViewById(R.id.app_icon);

appName.setText(data.loadLabel(packageManager));
packageName.setText(data.packageName);
iconview.setImageDrawable(data.loadIcon(packageManager));
}
return view;
}
};

如果在这里显示我的 fragment 类有任何用处,那就是:

package com.spicycurryman.getdisciplined10.app;

import android.app.ProgressDialog;
import android.content.ActivityNotFoundException;
import android.content.Intent;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.os.AsyncTask;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;
import android.widget.Toast;

import com.javatechig.listapps.ApplicationAdapter;

import java.util.ArrayList;
import java.util.List;


public class InstalledAppActivity extends Fragment {
private PackageManager packageManager = null;
private List<ApplicationInfo> applist = null;
private ApplicationAdapter listadaptor = null;

ListView InstalledAppList;

public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
packageManager = (PackageManager) getActivity().getPackageManager().getInstalledPackages(0);
new LoadApplications().execute();

InstalledAppList.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
ApplicationInfo app = applist.get(i);
try {
Intent intent = packageManager
.getLaunchIntentForPackage(app.packageName);

if (null != intent) {
startActivity(intent);
}
}

catch (ActivityNotFoundException e) {
Toast.makeText(getActivity(),"",Toast.LENGTH_SHORT).show();

}
}



});
return inflater.inflate(R.layout.installed_apps, container, false);

}


private List<ApplicationInfo> checkForLaunchIntent(List<ApplicationInfo> list) {
ArrayList<ApplicationInfo> applist = new ArrayList<ApplicationInfo>();
for (ApplicationInfo info : list) {
try {
if (null != packageManager.getLaunchIntentForPackage(info.packageName)) {
applist.add(info);
}
} catch (Exception e) {
e.printStackTrace();
}
}

return applist;
}

private class LoadApplications extends AsyncTask<Void, Void, Void> {
private ProgressDialog progress = null;

@Override
protected Void doInBackground(Void... params) {
applist = checkForLaunchIntent(packageManager.getInstalledApplications(PackageManager.GET_META_DATA));
listadaptor = new ApplicationAdapter(InstalledAppActivity.this,
R.layout.snippet_list_row, applist);

return null;
}

@Override
protected void onCancelled() {
super.onCancelled();
}

@Override
protected void onPostExecute(Void result) {
//setListAdapter(listadaptor);
InstalledAppList.setAdapter(listadaptor);
super.onPostExecute(result);
}



@Override
protected void onProgressUpdate(Void... values) {
super.onProgressUpdate(values);
}
}
}

错误是:

Cannot resolve method 'super(com.spicycurryman.getdisciplined10.app.InstalledActivity,int,java.util.List'

最佳答案

看起来 InstalledActivity 没有扩展/实现 Context,因此它不适用于任何 ArrayAdapter构造函数子句。

关于java - 无法在扩展 ArrayAdapter 的类中解析方法 super,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24347160/

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