java - 开始 Activity 时出错

标签 java android

我的阵列适配器类出现错误。错误出现在 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/

相关文章:

android - RecyclerView重叠没有阴影

java -/storage/emulated/0/Notes/(没有这样的文件或目录)?

java.lang.SecurityException : Permission denied (missing INTERNET permission? ) 即使在 android list 中添加此权限

java - 将字符串转换为对象名称。 IE。 R.string.对象名

java - 在 Java 中调试 - 设置 debugMode 标志

java - 将 Java 移植到 AS3

java - Box2D 让重力影响不同的质量

java - 使用 queryMap 进行 Spark 路由解析

java - Android 为什么应用程序可以在真实设备上的 Android Studio 上运行,但上传到商店后出现错误

android - 构建 CMake 时 Ninja 出现错误