java - 如何在 Android Java 中定义多重继承
问题描述
我的 manig=fest 中有两个我不明白的错误,希望有人能帮助我。我的清单中的错误都是与活动相关的错误:<activity android:name=".PersonListAdapter"/>
错误是:
- 它的类应该提供一个默认构造函数(一个没有参数的公共构造函数)
- PersonListAdapter 必须扩展 android.app.Activity - 关于此错误:如何定义该类从另一个类和 Android 应用程序扩展?
这是我的代码:
清单
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="co.il.applicationmoran">
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".register">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".peoplefinder"/>
<activity android:name=".PersonListAdapter"/>
<activity android:name=".login"/>
</application>
</manifest>
班级
package co.il.applicationmoran;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import java.util.ArrayList;
import java.util.List;
public class PersonListAdapter extends ArrayAdapter<person> {
private static String TAG = "PersonListAdapter";
private Context mycontext;
int myresource;
public PersonListAdapter(Context context, int resource, ArrayList<person> objects) {
super(context, resource, objects);
this.mycontext = context;
this.myresource=resource;
}
@NonNull
@Override
public View getView(int position, View convertView, ViewGroup parent) {
String name = getItem(position).getName();
String age=getItem(position).getAge();
String sex=getItem(position).getSex();
person person=new person(name,age,sex);
LayoutInflater inflater=LayoutInflater.from(mycontext);
convertView=inflater.inflate(myresource, parent, false);
TextView tvName=(TextView) convertView.findViewById(R.id.textview1);
TextView tvAge=(TextView) convertView.findViewById(R.id.textview2);
TextView tvSex=(TextView) convertView.findViewById(R.id.textview3);
tvName.setText(name);
tvAge.setText(age);
tvSex.setText(sex);
return convertView;
}
}
解决方案
- 可以将不带参数的公共构造函数添加为:
公共 PersonListAdapter() { }
- 适配器类不需要在清单文件中提及,您主要在清单中提及活动和服务类。从清单文件中删除以下行:
<activity android:name=".peoplefinder"/> //remoe if this is also not an activity class <activity android:name=".PersonListAdapter"/> //remove <activity android:name=".login"/> //remove if this is also not an activity class
推荐阅读
- javascript - 我正在尝试使用 react-redux 存储我的数据,但它没有。我该如何解决这个问题?
- azure-devops - 如何从 azure TFS 2019 日历板上删除休息日
- ios - 从项目 xcode 中删除 git
- c# - Excel 下载后无法读取数据
- c - 在哪里寻找 C 的 write 函数的文档
- git - 如何合并 2 个远程分支?
- python - Caddy 服务器、X-Forwarded-For 和欺骗值
- python - ImportError:没有名为 parse python/node js 的模块
- google-apps-script - 选择谷歌表格中每个指定列的下一个打开行的数据输入表单
- laravel - 在laravel中找不到列错误