Java 用于调用日志的惰性适配器
我已经创建了一个可以显示呼叫日志的应用程序。我正在使用Java 用于调用日志的惰性适配器,java,android,android-lazyadapter,Java,Android,Android Lazyadapter,我已经创建了一个可以显示呼叫日志的应用程序。我正在使用LazyAdapter类。我根据呼叫类型显示一个图标:未接/传入/传出。这部分工作不正常。除了通话类型外,姓名、号码、日期和时间等文本的显示都很好 以下是我试图做的: public class LazyAdapter extends BaseAdapter { private Activity activity; private ArrayList<HashMap<String, String>> data;
LazyAdapter
类。我根据呼叫类型显示一个图标:未接
/传入
/传出
。这部分工作不正常。除了通话类型外,姓名、号码、日期和时间等文本的显示都很好
以下是我试图做的:
public class LazyAdapter extends BaseAdapter
{
private Activity activity;
private ArrayList<HashMap<String, String>> data;
private static LayoutInflater inflater=null;
public LazyAdapter(Activity a, ArrayList<HashMap<String, String>> d)
{
activity = a;
data=d;
inflater = (LayoutInflater)activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
public int getCount()
{
return data.size();
}
public Object getItem(int position) {
return position;
}
public long getItemId(int position)
{
return position;
}
public View getView(int position, View convertView, ViewGroup parent)
{
View vi=convertView;
if(convertView==null)
vi = inflater.inflate(R.layout.callist, null);
TextView name = (TextView)vi.findViewById(R.id.name);
TextView number = (TextView)vi.findViewById(R.id.phone_number);
TextView date = (TextView)vi.findViewById(R.id.date);
TextView time = (TextView)vi.findViewById(R.id.time);
TextView duration = (TextView)vi.findViewById(R.id.duration);
ImageView callType = (ImageView)vi.findViewById(R.id.calType);
ImageView clock = (ImageView)vi.findViewById(R.id.Clock);
HashMap<String, String> pro = new HashMap<String, String>();
pro = data.get(position);
if((pro.get(ListOfCall.contactName)!=null))
{
name.setText(pro.get(ListOfCall.contactName));
}
else
{
name.setText("Unknown");
}
number.setText(pro.get(ListOfCall.phone));
date.setText(pro.get(ListOfCall.DateOfCall));
time.setText(pro.get(ListOfCall.TimeOfCall));
String type = pro.get(ListOfCall.typeofCall);
if(type.equalsIgnoreCase("OUTGOING"))
{
callType.setImageResource(R.drawable.outgoing);
duration.setText(pro.get(ListOfCall.durationOfCall));
}
else if(type.equalsIgnoreCase("INCOMING"))
{
callType.setImageResource(R.drawable.incoming);
duration.setText(pro.get(ListOfCall.durationOfCall));
}
else if(type.equalsIgnoreCase("MISSED"))
{
callType.setImageResource(R.drawable.missed);
duration.setVisibility(4);
clock.setVisibility(4);
}
return vi;
}
}
公共类LazyAdapter扩展了BaseAdapter
{
私人活动;
私有数组列表数据;
专用静态充气机=空;
公共LazyAdapter(活动a,ArrayList d)
{
活动=a;
数据=d;
充气器=(LayoutInflater)activity.getSystemService(Context.LAYOUT\u充气器\u SERVICE);
}
public int getCount()
{
返回data.size();
}
公共对象getItem(int位置){
返回位置;
}
公共长getItemId(int位置)
{
返回位置;
}
公共视图getView(int位置、视图转换视图、视图组父视图)
{
视图vi=转换视图;
if(convertView==null)
vi=充气机充气(R.layout.callist,空);
TextView name=(TextView)vi.findViewById(R.id.name);
TextView编号=(TextView)vi.findViewById(R.id.phone_编号);
TextView日期=(TextView)vi.findViewById(R.id.date);
TextView时间=(TextView)vi.findViewById(R.id.time);
TextView持续时间=(TextView)vi.findViewById(R.id.duration);
ImageView调用类型=(ImageView)vi.findViewById(R.id.calType);
ImageView时钟=(ImageView)vi.findViewById(R.id.clock);
HashMap pro=新的HashMap();
pro=data.get(位置);
if((pro.get(ListOfCall.contactName)!=null))
{
name.setText(pro.get(ListOfCall.contactName));
}
其他的
{
name.setText(“未知”);
}
number.setText(pro.get(ListOfCall.phone));
date.setText(pro.get(ListOfCall.DateOfCall));
time.setText(pro.get(ListOfCall.TimeOfCall));
字符串类型=pro.get(ListOfCall.typeofCall);
if(类型:equalsIgnoreCase(“传出”))
{
callType.setImageResource(R.drawable.outgoing);
duration.setText(pro.get(ListOfCall.durationOfCall));
}
else if(类型.equalsIgnoreCase(“传入”))
{
callType.setImageResource(R.drawable.incoming);
duration.setText(pro.get(ListOfCall.durationOfCall));
}
else if(类型.equalsIgnoreCase(“MISSED”))
{
callType.setImageResource(R.drawable.missed);
持续时间.能见度(4);
时钟设置可见性(4);
}
返回vi;
}
}
我不确定问题出在哪里,因为我能够在顶部名为data的arraylist
中得到正确的结果。当我将arraylist移动到名为pro的Hashmap
时,情况会发生变化
同样,除了调用类型和相应的图像没有显示外,其他值都正常显示
有人能帮我解决这个问题吗?发现LazyAdapter类中的条件没有按要求工作。删除该条件并将其添加到向LazyAdapter类发送值的before类中 现在一切正常 谢谢