private class ContactListAdapter extends ArrayAdapter<import_fragment.Contact> {
public ContactListAdapter() {
super (main_fragment.this, R.layout.fragment_import, Contacts);
}
@Override
public View getView(int position, View view, ViewGroup parent) {
if (view == null)
view = getActivity().getLayoutInflater().inflate(R.layout.fragment_import, parent, false);
import_fragment.Contact currentContact = Contacts.get(position);
TextView name = (TextView) view.findViewById(R.id.contactName);
name.setText(currentContact.getName());
TextView phone = (TextView) view.findViewById(R.id.phoneNumber);
phone.setText(currentContact.getPhone());
TextView email = (TextView) view.findViewById(R.id.emailAddress);
email.setText(currentContact.getEmail());
TextView address = (TextView) view.findViewById(R.id.cAddress);
address.setText(currentContact.getAddress());
return view;
}
当我尝试更改R.layout.import_fragment(我的其他片段)时,此行super (main_fragment.this, R.layout.fragment_import, Contacts);
有错误说*无法解析方法'super(com.al3almya.users.al3almya.main_fragment,int,java.util.List);
当我输入其他片段布局时,我收到此错误。
答案 0 :(得分:1)
ArrayAdapter
的第一个参数是Context
,但您传递com.al3almya.users.al3almya.main_fragment
,这是错误的。
将您的方法签名更改为此
public ContactListAdapter(Context cntx) {
super (cntx, R.layout.fragment_import, Contacts);
}
当你调用适配器时使用这个
new ContactListAdapter(this); // if called from activity
或
new ContactListAdapter(getActivity); // if called from fragment