2013-06-19 94 views
0

我創建了一個可以顯示呼叫日誌的應用程序。我正在使用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時,情況會發生變化。

再次,除了呼叫類型,值都會正常出現,並且相應的圖像不會出現。

有人可以幫我解決這個問題嗎?

回答

0

找出LazyAdapter類中的條件沒有按要求工作。刪除了條件,並在向LazyAdapter類發送值之前添加它們。

現在工作正常!

謝謝!