1.借助泛型,您可以使用单个ArrayList处理两个ArrayList。
例如在适配器中:
setListData(ArrayList<T> pListData)
{
mListData=pListData;
}
在视野中
getView(int position, View convertView, ViewGroup parent){
T commonModel= getItem(position);
if(T instanceof ArrayListOneModel){
ArrayListOneModel model1=(ArrayListOneModel)T;
do stuf for first arraylit...
}
}
- 如果您使用相同的模型,您可以为两个数组列表设置类型(枚举)
&在放映期间您可以检查这一点。
3.否则你可以先在arraylist中添加旧数据,然后使用collectionaddAll()在其中添加第二个最新消息列表。然后
adapter.notifyDataSetChanged()
将设置第一条旧消息,然后设置列表中的最新消息
更多说明:在第二种方法中,如果两个 arraylist 有不同的模型,则在两个模型中都包含一个枚举作为 setter getter。
public enum eType{
FIRST_LIST_TYPE,SECOND_LIST_TYPE
}
在从不同数据库的集合中获取数据期间,输入模型。
例如
public class model{
private enum eType;
// 来自数据库的其他 setter getter 值
/**
* 设置器获取器:
*/
public void seteType(enum eType)
{
this.eType = eType;
}
public enum geteType()
{
return eType;
}
}
在获取数据集类型期间,例如
Model model = new Model();
model.seteType(eType.FIRST_LIST_TYPE) ;
//same for 2nd db.
& simply check type inside getView() according to your requirement.