【问题标题】:Lazy Adapter for the Call Logs通话记录的惰性适配器
【发布时间】:2013-06-19 07:26:42
【问题描述】:

我创建了一个可以显示通话记录的应用程序。我正在使用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 调用数据中获得正确的结果。当我将数组列表移动到称为 pro 的 Hashmap 时,情况发生了变化。

除了调用类型和相应的图像没有出现之外,值再次正常出现。

有人可以帮我解决这个问题吗?

【问题讨论】:

    标签: java android android-lazyadapter


    【解决方案1】:

    发现 LazyAdapter 类中的条件没有按要求工作。删除条件并将它们添加到向 LazyAdapter 类发送值的类之前。

    现在可以正常使用了!!

    谢谢!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-05-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多