我有一个活动列表视图,我想在它的顶部附加数据。当活动加载时,列表视图被填充。现在当用户单击一个按钮时,我带来了额外的数据,但我希望这些数据附加在顶部的列表视图。我怎样才能做到这一点?
我使用baseAdapter
.Heres 我的 baseAdapter 类制作了自定义列表视图:
public class LazyAdapterUserAdminChats extends BaseAdapter{
private Activity activity;
private ArrayList<HashMap<String,String>> hashmap;
private static LayoutInflater inflater=null;
public LazyAdapterUserAdminChats(Activity activity,ArrayList<HashMap<String,String>> hashMaps)
{
this.activity=activity;
this.hashmap=hashMaps;
LazyAdapterUserAdminChats.inflater=(LayoutInflater)this.activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
@Override
public int getCount() {
return hashmap.size();
}
@Override
public Object getItem(int position) {
return position;
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View view=convertView;
if(convertView==null)
view=inflater.inflate(R.layout.useradminchat,null);
TextView username=(TextView)view.findViewById(R.id.UAC_userNametext);
TextView messagetext=(TextView)view.findViewById(R.id.UAC_messagetext);
TextView messageDate=(TextView)view.findViewById(R.id.UAC_dates);
HashMap<String,String> map=hashmap.get(position);
username.setText(map.get(HandleJSON.Key_username));
messagetext.setText(map.get(HandleJSON.Key_messageText));
messageDate.setText(map.get(HandleJSON.Key_messageDate));
return view;
}
}
以下是我如何从我的活动中为 listview 功能设置适配器。
private void ShowListView(ArrayList<HashMap<String,String>> chat)
{
try
{
ListView lv=(ListView)findViewById(android.R.id.list);
adapter = new LazyAdapterLatestChats(this,chat);
lv.setAdapter(adapter);
}
catch(Exception e)
{
Toast.makeText(this, e.getMessage(), Toast.LENGTH_LONG).show();
}
}