3
當我點擊較早的消息從數據庫中獲得,但列表視圖滾動到頂部未完成,該消息應該只裝載在列表視圖的頂部沒有加載負荷早些時候的消息其滾動。負載早些時候的消息像什麼應用
這裏是我的主要活動
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.private_group_chat);
Intent i = getIntent();
btnLoadMore = new Button(this);
btnLoadMore.setText("Load Earlier Messages");
lsvChat = (ListView) findViewById(R.id.lv_messsages);
lsvChat.addHeaderView(btnLoadMore);
chatModel = new ArrayList<ChatModel>();
db = new Database3(getApplicationContext());
chatModel = db.getSelectedIncidentDetails(getApplicationContext(),
groupId, count);
chatAdapter = new ChatAdapterGroup(getApplicationContext(), chatModel);
lsvChat.setAdapter(chatAdapter);
discoverModel = new ArrayList<DiscoverModel>();
dm = new DiscoverModel();
}
這裏是我的基本適配器的代碼......
public class ChatAdapterGroup extends BaseAdapter {
private Context context;
private LayoutInflater inflater;
int count = 0;
private ArrayList<ChatModel> list;
public ChatAdapterGroup(Context context, ArrayList<ChatModel> list) {
this.context = context;
this.list = list;
inflater = (LayoutInflater) context
.getSystemService(context.LAYOUT_INFLATER_SERVICE);
}
@Override
public int getCount() {
return list.size();
}
@Override
public Object getItem(int position) {
return list.get(position);
}
@Override
public long getItemId(int position) {
return position;
}
private class ViewHolder {
TextView txt_left;
TextView txt_right;
TextView tv_fromName;
RelativeLayout rl_left;
RelativeLayout rl_right;
}
@Override
public View getView(final int position, View v, ViewGroup arg2) {
final ViewHolder holder;
if (v == null) {
holder = new ViewHolder();
v = inflater.inflate(R.layout.chat_adapter, null);
holder.txt_left = (TextView) v.findViewById(R.id.txt_left);
holder.txt_right = (TextView) v.findViewById(R.id.txt_right);
holder.tv_fromName = (TextView) v.findViewById(R.id.tv_fromName);
holder.rl_left = (RelativeLayout) v.findViewById(R.id.rl_left);
holder.rl_right = (RelativeLayout) v.findViewById(R.id.rl_right);
v.setTag(holder);
} else {
holder = (ViewHolder) v.getTag();
}
if (list.get(position) != null) {
if (list.get(position).getGroup_cordinate()
.equalsIgnoreCase("left")) {
holder.txt_left.setText(""
+ list.get(position).getGroup_messages_recive());
holder.tv_fromName.setText(""
+ list.get(position).getFrom_name_recive());
holder.txt_left.setTextColor(Color.parseColor("#000000"));
holder.rl_right.setVisibility(View.GONE);
holder.rl_left.setVisibility(View.VISIBLE);
} else {
holder.txt_right.setText(""
+ list.get(position).getGroup_messages_recive());
holder.rl_left.setVisibility(View.GONE);
holder.rl_right.setVisibility(View.VISIBLE);
}
}
v.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
// notifyDataSetChanged();
}
});
return v;
}
}
和列表視圖中的XML編碼....... ......
<ListView
android:id="@+id/lv_messsages"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_above="@+id/ll_send"
android:layout_below="@+id/rl_header"
android:divider="@null"
android:stackFromBottom="true"
android:transcriptMode="alwaysScroll" />