我创建了一个可以显示通话记录的应用程序。我正在使用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移动到名为pro的Hashmap
时,事情发生了变化。
除了呼叫类型之外,值再次正确显示,并且相应的图像不会出现。
有人可以帮我解决这个问题吗?
答案 0 :(得分:0)
找出LazyAdapter类中的条件不能按要求工作。删除条件并在将值发送到LazyAdapter类的类之前添加它们。
现在工作正常!!
谢谢!