gpt4 book ai didi

java - 开始 Activity 时出错

转载 作者:行者123 更新时间:2023-11-29 21:16:06 25 4
gpt4 key购买 nike

我的阵列适配器类出现错误。错误出现在 Startavtivity 线上,我不知道为什么它在其他页面上工作,但它在此页面上显示错误。所以你能帮帮我吗

ERROR" The Constructor Intent(MyArrayAdapter,Class<Add_new_employee >undefined)

package com.example.employeemanager;

import java.util.ArrayList;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.TextView;
import android.widget.Toast;

public class MyArrayAdapter extends ArrayAdapter<Student> {

Context context;
int layoutResourceId;
ArrayList<Student> students = new ArrayList<Student>();

public MyArrayAdapter(Context context, int layoutResourceId,ArrayList<Student> studs)
{
super(context, layoutResourceId, studs);
this.layoutResourceId = layoutResourceId;
this.context = context;
this.students = studs;
}

@Override
public View getView(int position, View convertView, ViewGroup parent)
{
View item = convertView;
StudentWrapper StudentWrapper = null;

if (item == null)
{
LayoutInflater inflater = ((Activity) context).getLayoutInflater();
item = inflater.inflate(layoutResourceId, parent, false);
StudentWrapper = new StudentWrapper();
StudentWrapper.name = (TextView) item.findViewById(R.id.textName);
StudentWrapper.age = (TextView) item.findViewById(R.id.textAge);
StudentWrapper.address = (TextView) item.findViewById(R.id.textAddr);
StudentWrapper.edit = (Button) item.findViewById(R.id.btnEdit);
StudentWrapper.delete = (Button) item.findViewById(R.id.btnDelete);
StudentWrapper.checkBox = (CheckBox) item.findViewById(R.id.checkBox1);
item.setTag(StudentWrapper);
}
else
{
StudentWrapper = (StudentWrapper) item.getTag();
}

Student student = students.get(position);
StudentWrapper.name.setText(student.getName());
StudentWrapper.age.setText(student.getAge());
StudentWrapper.address.setText(student.getAddress());

StudentWrapper.edit.setOnClickListener(new OnClickListener() {
public void onClick(View v)
{
startActivity(new Intent
(MyArrayAdapter.this,Add_new_employee.class) );
}
});

StudentWrapper.delete.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
}
});

StudentWrapper.checkBox.setOnCheckedChangeListener(new OnCheckedChangeListener()
{
@Override
public void onCheckedChanged(CompoundButton arg0, boolean arg1) {
Toast.makeText(context, "Checkox", Toast.LENGTH_LONG).show();
}
});
return item;
}

protected void startActivity(Intent intent) {
// TODO Auto-generated method stub
}

static class StudentWrapper
{
TextView name;
TextView age;
TextView address;
Button edit;
Button delete;
CheckBox checkBox;
}
}

最佳答案

插入这个

startActivity(new Intent   

(MyArrayAdapter.this,Add_new_employee.class) );

用这个

context.startActivity(new Intent   

(context,Add_new_employee.class) );

注意:确保您已经在 android manifest.xml 中声明了 Add_new_employee

关于java - 开始 Activity 时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21398021/

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