2
我正在構建一個聊天應用程序,我需要滾動到加載更多數據。 但是,當我撥打notifyDataSetChanged()
我的ListView
滾動到底部。Android - 防止滾動到底部上notifyDataSetChanged()
我ListView
:
<ListView
android:id="@+id/list_messages"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:transcriptMode="alwaysScroll"
android:stackFromBottom="true">
</ListView>
我BaseAdapter
就像這樣:
public class CompleteListAdapter extends BaseAdapter {
private Activity mContext;
private List<String> mList;
private LayoutInflater mLayoutInflater = null;
public CompleteListAdapter(Activity context, List<String> list) {
mContext = context;
mList = list;
mLayoutInflater = (LayoutInflater) mContext
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
@Override
public int getCount() {
return mList.size();
}
@Override
public Object getItem(int pos) {
return mList.get(pos);
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View v = convertView;
CompleteListViewHolder viewHolder;
if (convertView == null) {
LayoutInflater li = (LayoutInflater) mContext
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
v = li.inflate(R.layout.list_layout, null);
viewHolder = new CompleteListViewHolder(v);
v.setTag(viewHolder);
} else {
viewHolder = (CompleteListViewHolder) v.getTag();
}
viewHolder.mTVItem.setText(mList.get(position));
return v;
} } class CompleteListViewHolder {
public TextView mTVItem;
public CompleteListViewHolder(View base) {
mTVItem = (TextView) base.findViewById(R.id.listTV);
}
}
如何防止滾動列表底部?