Android 如何在单击项目详细信息视图时创建包含4个子项目的ListView

Android 如何在单击项目详细信息视图时创建包含4个子项目的ListView,android,listview,android-listview,import,Android,Listview,Android Listview,Import,如何创建包含姓名、电话、手机和电子邮件的4个子项的列表视图 我是一个非常新的android学习者 例: 下面是我的代码,其中每个列表项显示一行GMOFragment.java import android.content.Intent; import android.os.Bundle; import android.os.Parcelable; import android.view.LayoutInflater; import android.view.View; import androi

如何创建包含姓名、电话、手机和电子邮件的4个子项的列表视图

我是一个非常新的android学习者

例:

下面是我的代码,其中每个列表项显示一行GMOFragment.java

import android.content.Intent;
import android.os.Bundle;
import android.os.Parcelable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.Toast;

import com.rupomkhondaker.sonalibank.adapter.PhoneListAdapter;
import com.rupomkhondaker.sonalibank.model.ContactItem;


import java.io.Serializable;
import java.util.ArrayList;

public class GMOFragment extends android.app.Fragment {
    public GMOFragment(){}


    private ArrayList<ContactItem> phoneItems;
    private PhoneListAdapter adapters;


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {

        View rootView = inflater.inflate(R.layout.fragment_gmo, container, false);



        ArrayList<ContactItem> listData = getListData();

        final ListView listView = (ListView) rootView.findViewById(R.id.gmolistView);
        listView.setAdapter(new PhoneListAdapter(getActivity(), listData));

        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {

            @Override
            public void onItemClick(AdapterView<?> a, View v, int position, long id) {
                ContactItem newsData = (ContactItem) listView.getItemAtPosition(position);

                Toast.makeText(getActivity(), "Selected :" + " " + newsData, Toast.LENGTH_LONG).show();
                Intent in = new Intent(getActivity(), ContactDetail.class);
                // sending data to new activity

      //!!! I NEED HELP HERE !!!!

                //
                startActivity(in);
            }
        });


        return rootView;
    }

  private ArrayList<ContactItem> getListData() {
        ArrayList<ContactItem> listMockData = new ArrayList<ContactItem>();
        String[] names = getResources().getStringArray(R.array.gmo_name_list);
        String[] phones = getResources().getStringArray(R.array.gmo_ph_list);
        String[] mobiles = getResources().getStringArray(R.array.gmo_mob_list);
        String[] emails = getResources().getStringArray(R.array.gmo_email_list);

        for (int i = 0; i < names.length; i++) {
            ContactItem newsData = new ContactItem();
            newsData.setName(names[i]);
            newsData.setPhone(phones[i]);
            newsData.setMobile(mobiles[i]);
            newsData.setEmail(emails[i]);

            listMockData.add(newsData);
        }
        return listMockData;
    }
}
public class CustomAdapter extends ArrayAdapter<CustomObject> {

    public CustomAdapter(Context context, List<CustomObject> objects) {
        super(context, -1, objects);
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder;
        View view = convertView;
        if (view == null) {
            view = View.inflate(getContext(), R.layout.list_view_item, null);
            viewHolder = new ViewHolder();
            viewHolder.setView(view);
        } else {
            viewHolder = (ViewHolder) view.getTag();
        }

        viewHolder.mName.setText(getItem(position).getName());
        viewHolder.mPhone.setText(getItem(position).getPhone());
        viewHolder.mMobile.setText(getItem(position).getMobile());
        viewHolder.mEmail.setText(getItem(position).getEmail());

        return view;
    }

    private class ViewHolder {

        public TextView mName;
        public TextView mPhone;
        public TextView mMobile;
        public TextView mEmail;

        public void setView(View view) {
            mName = (TextView) view.findViewById(R.id.textView);
            mPhone = (TextView) view.findViewById(R.id.textView2);
            mMobile = (TextView) view.findViewById(R.id.textView3);
            mEmail = (TextView) view.findViewById(R.id.textView4);
            view.setTag(this);
        }

    }
}
public class CustomObject implements Parcelable {

    public String mName;
    public String mPhone;
    public String mMobile;
    public String mEmail;

    public CustomObject(String name, String phone, String mobile, String email) {
        mName = name;
        mPhone = phone;
        mMobile = mobile;
        mEmail = email;
    }

    private CustomObject(Parcel parcel) {
        readFromParcel(parcel);
    }

    public String getName() {
        return mName;
    }

    public void setName(String name) {
        mName = name;
    }

    public String getPhone() {
        return mPhone;
    }

    public void setPhone(String phone) {
        mPhone = phone;
    }

    public String getMobile() {
        return mMobile;
    }

    public void setMobile(String mobile) {
        mMobile = mobile;
    }

    public String getEmail() {
        return mEmail;
    }

    public void setEmail(String email) {
        mEmail = email;
    }

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeString(mName);
        dest.writeString(mPhone);
        dest.writeString(mMobile);
        dest.writeString(mEmail);
    }

    private void readFromParcel(Parcel parcel) {
        mName = parcel.readString();
        mPhone = parcel.readString();
        mMobile = parcel.readString();
        mEmail = parcel.readString();
    }

    public static final Creator<CustomObject> CREATOR = new Creator<CustomObject>() {
        @Override
        public CustomObject createFromParcel(Parcel source) {
            return new CustomObject(source);
        }

        @Override
        public CustomObject[] newArray(int size) {
            return new CustomObject[0];
        }
    };
}
public class MainActivity extends Activity {


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        ListView listView = (ListView) findViewById(R.id.listView);

        ArrayList<CustomObject> customObjects = new ArrayList<>();
        for (int i = 0; i < 5; i++) {
            CustomObject customObject = new CustomObject("Name", "Phone", "Mobile", "Email");
            customObjects.add(customObject);
        }

        CustomAdapter customAdapter = new CustomAdapter(this, customObjects);
        listView.setAdapter(customAdapter);

        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            CustomObject object = customAdapter.getItem(position);
            Intent intent = new Intent(this, NextActivity.class);
            intent.putExtra("Item", customObjects);
            startActivity(intent);
        }
    });
    }

}

您需要创建自己的自定义适配器和自定义视图

查看以下教程-

如果你理解这个概念有困难,请告诉我

这是一个工作代码-

自定义适配器-

import android.content.Intent;
import android.os.Bundle;
import android.os.Parcelable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.Toast;

import com.rupomkhondaker.sonalibank.adapter.PhoneListAdapter;
import com.rupomkhondaker.sonalibank.model.ContactItem;


import java.io.Serializable;
import java.util.ArrayList;

public class GMOFragment extends android.app.Fragment {
    public GMOFragment(){}


    private ArrayList<ContactItem> phoneItems;
    private PhoneListAdapter adapters;


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {

        View rootView = inflater.inflate(R.layout.fragment_gmo, container, false);



        ArrayList<ContactItem> listData = getListData();

        final ListView listView = (ListView) rootView.findViewById(R.id.gmolistView);
        listView.setAdapter(new PhoneListAdapter(getActivity(), listData));

        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {

            @Override
            public void onItemClick(AdapterView<?> a, View v, int position, long id) {
                ContactItem newsData = (ContactItem) listView.getItemAtPosition(position);

                Toast.makeText(getActivity(), "Selected :" + " " + newsData, Toast.LENGTH_LONG).show();
                Intent in = new Intent(getActivity(), ContactDetail.class);
                // sending data to new activity

      //!!! I NEED HELP HERE !!!!

                //
                startActivity(in);
            }
        });


        return rootView;
    }

  private ArrayList<ContactItem> getListData() {
        ArrayList<ContactItem> listMockData = new ArrayList<ContactItem>();
        String[] names = getResources().getStringArray(R.array.gmo_name_list);
        String[] phones = getResources().getStringArray(R.array.gmo_ph_list);
        String[] mobiles = getResources().getStringArray(R.array.gmo_mob_list);
        String[] emails = getResources().getStringArray(R.array.gmo_email_list);

        for (int i = 0; i < names.length; i++) {
            ContactItem newsData = new ContactItem();
            newsData.setName(names[i]);
            newsData.setPhone(phones[i]);
            newsData.setMobile(mobiles[i]);
            newsData.setEmail(emails[i]);

            listMockData.add(newsData);
        }
        return listMockData;
    }
}
public class CustomAdapter extends ArrayAdapter<CustomObject> {

    public CustomAdapter(Context context, List<CustomObject> objects) {
        super(context, -1, objects);
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder;
        View view = convertView;
        if (view == null) {
            view = View.inflate(getContext(), R.layout.list_view_item, null);
            viewHolder = new ViewHolder();
            viewHolder.setView(view);
        } else {
            viewHolder = (ViewHolder) view.getTag();
        }

        viewHolder.mName.setText(getItem(position).getName());
        viewHolder.mPhone.setText(getItem(position).getPhone());
        viewHolder.mMobile.setText(getItem(position).getMobile());
        viewHolder.mEmail.setText(getItem(position).getEmail());

        return view;
    }

    private class ViewHolder {

        public TextView mName;
        public TextView mPhone;
        public TextView mMobile;
        public TextView mEmail;

        public void setView(View view) {
            mName = (TextView) view.findViewById(R.id.textView);
            mPhone = (TextView) view.findViewById(R.id.textView2);
            mMobile = (TextView) view.findViewById(R.id.textView3);
            mEmail = (TextView) view.findViewById(R.id.textView4);
            view.setTag(this);
        }

    }
}
public class CustomObject implements Parcelable {

    public String mName;
    public String mPhone;
    public String mMobile;
    public String mEmail;

    public CustomObject(String name, String phone, String mobile, String email) {
        mName = name;
        mPhone = phone;
        mMobile = mobile;
        mEmail = email;
    }

    private CustomObject(Parcel parcel) {
        readFromParcel(parcel);
    }

    public String getName() {
        return mName;
    }

    public void setName(String name) {
        mName = name;
    }

    public String getPhone() {
        return mPhone;
    }

    public void setPhone(String phone) {
        mPhone = phone;
    }

    public String getMobile() {
        return mMobile;
    }

    public void setMobile(String mobile) {
        mMobile = mobile;
    }

    public String getEmail() {
        return mEmail;
    }

    public void setEmail(String email) {
        mEmail = email;
    }

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeString(mName);
        dest.writeString(mPhone);
        dest.writeString(mMobile);
        dest.writeString(mEmail);
    }

    private void readFromParcel(Parcel parcel) {
        mName = parcel.readString();
        mPhone = parcel.readString();
        mMobile = parcel.readString();
        mEmail = parcel.readString();
    }

    public static final Creator<CustomObject> CREATOR = new Creator<CustomObject>() {
        @Override
        public CustomObject createFromParcel(Parcel source) {
            return new CustomObject(source);
        }

        @Override
        public CustomObject[] newArray(int size) {
            return new CustomObject[0];
        }
    };
}
public class MainActivity extends Activity {


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        ListView listView = (ListView) findViewById(R.id.listView);

        ArrayList<CustomObject> customObjects = new ArrayList<>();
        for (int i = 0; i < 5; i++) {
            CustomObject customObject = new CustomObject("Name", "Phone", "Mobile", "Email");
            customObjects.add(customObject);
        }

        CustomAdapter customAdapter = new CustomAdapter(this, customObjects);
        listView.setAdapter(customAdapter);

        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            CustomObject object = customAdapter.getItem(position);
            Intent intent = new Intent(this, NextActivity.class);
            intent.putExtra("Item", customObjects);
            startActivity(intent);
        }
    });
    }

}
公共类CustomAdapter扩展了ArrayAdapter{
公共CustomAdapter(上下文、列表对象){
super(上下文,-1,对象);
}
@凌驾
公共视图getView(int位置、视图转换视图、视图组父视图){
持票人持票人;
视图=转换视图;
如果(视图==null){
视图=视图.充气(getContext(),R.layout.list\u视图\u项,null);
viewHolder=新的viewHolder();
viewHolder.setView(视图);
}否则{
viewHolder=(viewHolder)view.getTag();
}
viewHolder.mName.setText(getItem(position.getName());
viewHolder.mPhone.setText(getItem(position.getPhone());
viewHolder.mMobile.setText(getItem(position.getMobile());
viewHolder.mEmail.setText(getItem(position.getEmail());
返回视图;
}
私有类视窗持有者{
公共文本视图mName;
公共文本视图mPhone;
公共文本视图;
公共文本视图mEmail;
公共无效集合视图(视图){
mName=(TextView)view.findViewById(R.id.TextView);
mPhone=(TextView)view.findViewById(R.id.textView2);
mMobile=(TextView)view.findViewById(R.id.textView3);
mEmail=(TextView)view.findViewById(R.id.textView4);
view.setTag(this);
}
}
}
自定义对象-

import android.content.Intent;
import android.os.Bundle;
import android.os.Parcelable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.Toast;

import com.rupomkhondaker.sonalibank.adapter.PhoneListAdapter;
import com.rupomkhondaker.sonalibank.model.ContactItem;


import java.io.Serializable;
import java.util.ArrayList;

public class GMOFragment extends android.app.Fragment {
    public GMOFragment(){}


    private ArrayList<ContactItem> phoneItems;
    private PhoneListAdapter adapters;


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {

        View rootView = inflater.inflate(R.layout.fragment_gmo, container, false);



        ArrayList<ContactItem> listData = getListData();

        final ListView listView = (ListView) rootView.findViewById(R.id.gmolistView);
        listView.setAdapter(new PhoneListAdapter(getActivity(), listData));

        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {

            @Override
            public void onItemClick(AdapterView<?> a, View v, int position, long id) {
                ContactItem newsData = (ContactItem) listView.getItemAtPosition(position);

                Toast.makeText(getActivity(), "Selected :" + " " + newsData, Toast.LENGTH_LONG).show();
                Intent in = new Intent(getActivity(), ContactDetail.class);
                // sending data to new activity

      //!!! I NEED HELP HERE !!!!

                //
                startActivity(in);
            }
        });


        return rootView;
    }

  private ArrayList<ContactItem> getListData() {
        ArrayList<ContactItem> listMockData = new ArrayList<ContactItem>();
        String[] names = getResources().getStringArray(R.array.gmo_name_list);
        String[] phones = getResources().getStringArray(R.array.gmo_ph_list);
        String[] mobiles = getResources().getStringArray(R.array.gmo_mob_list);
        String[] emails = getResources().getStringArray(R.array.gmo_email_list);

        for (int i = 0; i < names.length; i++) {
            ContactItem newsData = new ContactItem();
            newsData.setName(names[i]);
            newsData.setPhone(phones[i]);
            newsData.setMobile(mobiles[i]);
            newsData.setEmail(emails[i]);

            listMockData.add(newsData);
        }
        return listMockData;
    }
}
public class CustomAdapter extends ArrayAdapter<CustomObject> {

    public CustomAdapter(Context context, List<CustomObject> objects) {
        super(context, -1, objects);
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder;
        View view = convertView;
        if (view == null) {
            view = View.inflate(getContext(), R.layout.list_view_item, null);
            viewHolder = new ViewHolder();
            viewHolder.setView(view);
        } else {
            viewHolder = (ViewHolder) view.getTag();
        }

        viewHolder.mName.setText(getItem(position).getName());
        viewHolder.mPhone.setText(getItem(position).getPhone());
        viewHolder.mMobile.setText(getItem(position).getMobile());
        viewHolder.mEmail.setText(getItem(position).getEmail());

        return view;
    }

    private class ViewHolder {

        public TextView mName;
        public TextView mPhone;
        public TextView mMobile;
        public TextView mEmail;

        public void setView(View view) {
            mName = (TextView) view.findViewById(R.id.textView);
            mPhone = (TextView) view.findViewById(R.id.textView2);
            mMobile = (TextView) view.findViewById(R.id.textView3);
            mEmail = (TextView) view.findViewById(R.id.textView4);
            view.setTag(this);
        }

    }
}
public class CustomObject implements Parcelable {

    public String mName;
    public String mPhone;
    public String mMobile;
    public String mEmail;

    public CustomObject(String name, String phone, String mobile, String email) {
        mName = name;
        mPhone = phone;
        mMobile = mobile;
        mEmail = email;
    }

    private CustomObject(Parcel parcel) {
        readFromParcel(parcel);
    }

    public String getName() {
        return mName;
    }

    public void setName(String name) {
        mName = name;
    }

    public String getPhone() {
        return mPhone;
    }

    public void setPhone(String phone) {
        mPhone = phone;
    }

    public String getMobile() {
        return mMobile;
    }

    public void setMobile(String mobile) {
        mMobile = mobile;
    }

    public String getEmail() {
        return mEmail;
    }

    public void setEmail(String email) {
        mEmail = email;
    }

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeString(mName);
        dest.writeString(mPhone);
        dest.writeString(mMobile);
        dest.writeString(mEmail);
    }

    private void readFromParcel(Parcel parcel) {
        mName = parcel.readString();
        mPhone = parcel.readString();
        mMobile = parcel.readString();
        mEmail = parcel.readString();
    }

    public static final Creator<CustomObject> CREATOR = new Creator<CustomObject>() {
        @Override
        public CustomObject createFromParcel(Parcel source) {
            return new CustomObject(source);
        }

        @Override
        public CustomObject[] newArray(int size) {
            return new CustomObject[0];
        }
    };
}
public class MainActivity extends Activity {


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        ListView listView = (ListView) findViewById(R.id.listView);

        ArrayList<CustomObject> customObjects = new ArrayList<>();
        for (int i = 0; i < 5; i++) {
            CustomObject customObject = new CustomObject("Name", "Phone", "Mobile", "Email");
            customObjects.add(customObject);
        }

        CustomAdapter customAdapter = new CustomAdapter(this, customObjects);
        listView.setAdapter(customAdapter);

        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            CustomObject object = customAdapter.getItem(position);
            Intent intent = new Intent(this, NextActivity.class);
            intent.putExtra("Item", customObjects);
            startActivity(intent);
        }
    });
    }

}
public类CustomObject实现可包裹{
公共字符串mName;
公共字符串mPhone;
公共交通工具;
公共字符串mEmail;
公共CustomObject(字符串名称、字符串电话、字符串手机、字符串电子邮件){
mName=名称;
mPhone=电话;
mMobile=移动设备;
mEmail=电子邮件;
}
专用自定义对象(地块){
阅读包裹(包裹);
}
公共字符串getName(){
返回mName;
}
公共void集合名(字符串名){
mName=名称;
}
公共字符串getPhone(){
返回mPhone;
}
公用无效设置电话(字符串电话){
mPhone=电话;
}
公共字符串getMobile(){
返回车;
}
公共void setMobile(字符串移动){
mMobile=移动设备;
}
公共字符串getEmail(){
返回mEmail;
}
公用电子邮件(字符串电子邮件){
mEmail=电子邮件;
}
@凌驾
公共int描述内容(){
返回0;
}
@凌驾
公共无效写入包裹(包裹目的地,内部标志){
目的地记录(mName);
目的地记录(mPhone);
目的地书面资本(mMobile);
目的地书面限制(mEmail);
}
私人作废readFromParcel(地块){
mName=parcel.readString();
mPhone=parcel.readString();
mMobile=parcel.readString();
mEmail=parcel.readString();
}
公共静态最终创建者=新创建者(){
@凌驾
公共CustomObject createFromParcel(地块源){
返回新的CustomObject(源);
}
@凌驾
公共CustomObject[]新数组(整数大小){
返回新的CustomObject[0];
}
};
}
您的活动-

import android.content.Intent;
import android.os.Bundle;
import android.os.Parcelable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.Toast;

import com.rupomkhondaker.sonalibank.adapter.PhoneListAdapter;
import com.rupomkhondaker.sonalibank.model.ContactItem;


import java.io.Serializable;
import java.util.ArrayList;

public class GMOFragment extends android.app.Fragment {
    public GMOFragment(){}


    private ArrayList<ContactItem> phoneItems;
    private PhoneListAdapter adapters;


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {

        View rootView = inflater.inflate(R.layout.fragment_gmo, container, false);



        ArrayList<ContactItem> listData = getListData();

        final ListView listView = (ListView) rootView.findViewById(R.id.gmolistView);
        listView.setAdapter(new PhoneListAdapter(getActivity(), listData));

        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {

            @Override
            public void onItemClick(AdapterView<?> a, View v, int position, long id) {
                ContactItem newsData = (ContactItem) listView.getItemAtPosition(position);

                Toast.makeText(getActivity(), "Selected :" + " " + newsData, Toast.LENGTH_LONG).show();
                Intent in = new Intent(getActivity(), ContactDetail.class);
                // sending data to new activity

      //!!! I NEED HELP HERE !!!!

                //
                startActivity(in);
            }
        });


        return rootView;
    }

  private ArrayList<ContactItem> getListData() {
        ArrayList<ContactItem> listMockData = new ArrayList<ContactItem>();
        String[] names = getResources().getStringArray(R.array.gmo_name_list);
        String[] phones = getResources().getStringArray(R.array.gmo_ph_list);
        String[] mobiles = getResources().getStringArray(R.array.gmo_mob_list);
        String[] emails = getResources().getStringArray(R.array.gmo_email_list);

        for (int i = 0; i < names.length; i++) {
            ContactItem newsData = new ContactItem();
            newsData.setName(names[i]);
            newsData.setPhone(phones[i]);
            newsData.setMobile(mobiles[i]);
            newsData.setEmail(emails[i]);

            listMockData.add(newsData);
        }
        return listMockData;
    }
}
public class CustomAdapter extends ArrayAdapter<CustomObject> {

    public CustomAdapter(Context context, List<CustomObject> objects) {
        super(context, -1, objects);
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder;
        View view = convertView;
        if (view == null) {
            view = View.inflate(getContext(), R.layout.list_view_item, null);
            viewHolder = new ViewHolder();
            viewHolder.setView(view);
        } else {
            viewHolder = (ViewHolder) view.getTag();
        }

        viewHolder.mName.setText(getItem(position).getName());
        viewHolder.mPhone.setText(getItem(position).getPhone());
        viewHolder.mMobile.setText(getItem(position).getMobile());
        viewHolder.mEmail.setText(getItem(position).getEmail());

        return view;
    }

    private class ViewHolder {

        public TextView mName;
        public TextView mPhone;
        public TextView mMobile;
        public TextView mEmail;

        public void setView(View view) {
            mName = (TextView) view.findViewById(R.id.textView);
            mPhone = (TextView) view.findViewById(R.id.textView2);
            mMobile = (TextView) view.findViewById(R.id.textView3);
            mEmail = (TextView) view.findViewById(R.id.textView4);
            view.setTag(this);
        }

    }
}
public class CustomObject implements Parcelable {

    public String mName;
    public String mPhone;
    public String mMobile;
    public String mEmail;

    public CustomObject(String name, String phone, String mobile, String email) {
        mName = name;
        mPhone = phone;
        mMobile = mobile;
        mEmail = email;
    }

    private CustomObject(Parcel parcel) {
        readFromParcel(parcel);
    }

    public String getName() {
        return mName;
    }

    public void setName(String name) {
        mName = name;
    }

    public String getPhone() {
        return mPhone;
    }

    public void setPhone(String phone) {
        mPhone = phone;
    }

    public String getMobile() {
        return mMobile;
    }

    public void setMobile(String mobile) {
        mMobile = mobile;
    }

    public String getEmail() {
        return mEmail;
    }

    public void setEmail(String email) {
        mEmail = email;
    }

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeString(mName);
        dest.writeString(mPhone);
        dest.writeString(mMobile);
        dest.writeString(mEmail);
    }

    private void readFromParcel(Parcel parcel) {
        mName = parcel.readString();
        mPhone = parcel.readString();
        mMobile = parcel.readString();
        mEmail = parcel.readString();
    }

    public static final Creator<CustomObject> CREATOR = new Creator<CustomObject>() {
        @Override
        public CustomObject createFromParcel(Parcel source) {
            return new CustomObject(source);
        }

        @Override
        public CustomObject[] newArray(int size) {
            return new CustomObject[0];
        }
    };
}
public class MainActivity extends Activity {


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        ListView listView = (ListView) findViewById(R.id.listView);

        ArrayList<CustomObject> customObjects = new ArrayList<>();
        for (int i = 0; i < 5; i++) {
            CustomObject customObject = new CustomObject("Name", "Phone", "Mobile", "Email");
            customObjects.add(customObject);
        }

        CustomAdapter customAdapter = new CustomAdapter(this, customObjects);
        listView.setAdapter(customAdapter);

        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            CustomObject object = customAdapter.getItem(position);
            Intent intent = new Intent(this, NextActivity.class);
            intent.putExtra("Item", customObjects);
            startActivity(intent);
        }
    });
    }

}
公共类MainActivity扩展活动{
@凌驾
创建时受保护的void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ListView ListView=(ListView)findViewById(R.id.ListView);
ArrayList customObjects=新的ArrayList();
对于(int i=0;i<5;i++){
CustomObject CustomObject=新的CustomObject(“姓名”、“电话”、“手机”、“电子邮件”);
customObjects.add(customObject);
}
CustomAdapter CustomAdapter=新的CustomAdapter(这是customObjects);
setAdapter(customAdapter);
setOnItemClickListener(新的AdapterView.OnItemClickListener(){
@凌驾
public void onItemClick(AdapterView父对象、视图、整型位置、长id){
CustomObject对象=customAdapter.getItem(位置);
Intent Intent=新的Intent(this,nextractivity.class);
intent.putExtra(“项目”,customObjects);
星触觉(意向);
}
});
}
}
自定义视图(list\u View\u item.xml)-


activity_main.xml-

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
                xmlns:tools="http://schemas.android.com/tools"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:paddingLeft="@dimen/activity_horizontal_margin"
                android:paddingRight="@dimen/activity_horizontal_margin"
                android:paddingTop="@dimen/activity_vertical_margin"
                android:paddingBottom="@dimen/activity_vertical_margin"
                tools:context=".MainActivity">

    <ListView
        android:id="@+id/listView"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

</RelativeLayout>


如果有任何不合理的地方,请告诉我,我会向您解释。

谢谢您提供的教程。我是个新手,请你帮我用我的代码实现你的方法好吗?
CustomObject(“Abc”、“Abc”、“Abc”、“Abc”)代表?如何设置我的数据源`ArrayList数据;私有字符串[]gmoString,gmophItem;gmomobItem;gmomailItem;`而不是CustomObject(“Abc”、“Abc”、“Abc”、“Abc”);你有Java或其他编程语言的经验吗?我这样问是因为我知道这会让我更好地帮助你。我已经更新了我的答案。CustomObject(“Abc”、“Abc”、“Abc”、“Abc”);将创建CustomObject的新实例,其中第一个参数代表名称,第二个代表电话,第三个代表手机,第四个代表电子邮件。在类和活动之间传递四个值,因此在这里创建自定义对象更有意义,这将消除使用HashM的需要,从而消除代码的复杂性