我创建了一个可以显示通话记录的应用程序。我正在使用LazyAdapter
类。我根据呼叫类型显示一个图标:Missed
// 。这部分工作不正常。除了呼叫类型,姓名、号码、日期和时间等文本的显示是否正常?Incoming
Outgoing
这是我正在尝试做的事情:
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;
}
}
我不确定问题出在哪里,因为我能够arraylist
在顶部的调用数据中获得正确的结果。当我将 arraylist 移动到Hashmap
称为 pro 时,情况发生了变化。
除了调用类型和相应的图像没有出现之外,这些值再次正常出现。
有人可以帮我解决这个问题吗?