활동에 listview가 있고 그 위에 데이터를 추가하고 싶습니다. 활동이로드되면 listview가 채워집니다. 사용자가 버튼을 클릭하면 i 추가 데이터를 가져오고 있지만이 데이터를 목록보기 맨 위에 추가하고 싶습니다. 어떻게이 작업을 수행 할 수 있습니까?기존 목록 뷰의 맨 위에있는 요소를 android에 추가하십시오.
은 내가 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;
}
}
여기 내 활동에서 목록보기 기능에 대한 어댑터를 설정하는 방법입니다.
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();
}
}
목록보기 맨 위에 추가하는 방법. adivce 주셔서 감사합니다. – Mj1992
코드 예제를 통해 나를 설명 할 수 있습니까? – Mj1992
자신의 개체 arraylist를 사용하십시오. 왜 해시 맵의 arraylist가 필요합니까? 당신은 자바에 상당히 새로운가요? arraylist의 머리에 추가하고 싶다면 alObj.add (object, index)를 호출하면됩니다. 이 경우 인덱스는 0이됩니다. –