Fragment内Adapter数据刷新后界面数据为什么只显示了一条
public class CopyOfPersonDynamic extends DemoListFragment {
View mRootView;
private Context mContext;
private ListView mListView;
private DataAdapter mAdapter;
private Handler mHandler;
@Override
public View onCreateView(LayoutInflater mInflater,
@Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
mHandler = new Handler(Looper.getMainLooper()) {
@Override
public void handleMessage(Message msg) {
super.handleMessage(msg);
mAdapter.refreshDataAdapter();
mListView.requestLayout();
mAdapter.notifyDataSetChanged();
}
};
mContext = container.getContext();
mRootView = mInflater.inflate(R.layout.tabroot, null);
mListView = (ListView) mRootView.findViewById(R.id.dynamicList);
mAdapter = new DataAdapter();
mListView.setAdapter(mAdapter);
mListView.setClickable(true);
mListView.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
Intent it = new Intent(getActivity(), DemoActivity.class);
startActivity(it);
}
});
refreshTask();
return mRootView;
}
private void refreshTask() {
Timer timer = new Timer(false);
TimerTask task = new TimerTask() {
@Override
public void run() {
// TODO Auto-generated method stub
if (GetData.getData())
mHandler.sendEmptyMessage(1);
}
};
timer.schedule(task, 1);
}
private class DataAdapter extends BaseAdapter {
ArrayList<String> mArrs = new ArrayList<String>();
@Override
public int getCount() {
if (mArrs != null)
return mArrs.size();
else
return 0;
}
public void refreshDataAdapter() {
if (mArrs != null)
mArrs.clear();
mArrs.addAll(GetData.mDatas);
}
@Override
public Object getItem(int position) {
return null;
}
@Override
public long getItemId(int position) {
return 0;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
if (convertView == null) {
convertView = LayoutInflater.from(getActivity()).inflate(
R.layout.item, null);
}
int temp = mArrs.size() - 1 - position;// 倒序
if (temp >= 0 && temp < mArrs.size()) {
setItemValue(temp, convertView);
}
return convertView;
}
private void setItemValue(final int position, View convertView) {
TextView releasetime = (TextView) convertView
.findViewById(R.id.releasetime);
releasetime.setText(mArrs.get(position));
}
}
}
测试发现界面上一直都只显示第一条数据,可是我输出显示mArrs的数据是确定不止一条数据的,即数据获取是没有问题的,到底是哪里出问题了呢?在线等......
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
功能上没有错,只是布局文件的listview外层是一个ScrollView导致的,改了就好了