https://github.com/johannilsson/android-pulltorefresh
我从上面的链接中采取了示例..当项目数少于可滚动项目时,我无法刷新它。
以下是我的活动类
中的代码@Override
public void onRefresh() {
System.out.println("on refresh");
// disAll();
new GetDataTask().execute();
// listDisply.onRefreshComplete();
}
private class GetDataTask extends AsyncTask<Void, Void, String[]> {
@Override
protected String[] doInBackground(Void... params) {
// Simulates a background job.
System.out.println("do in background");
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
}
return null;
}
@Override
protected void onPostExecute(String[] result) {
// mListItems.addFirst("Added after refresh...");
System.out.println("on post execute");
loadData();
scAdapter.notifyDataSetChanged();
// Call onRefreshComplete when the list has been refreshed.
listDisply.onRefreshComplete();
super.onPostExecute(result);
}
}
oncreateview中的代码(我使用片段)
listDisply = (PullToRefreshListView) v.findViewById(R.id.lvList);
listDisply.setOnRefreshListener(this);
我的代码为setAdapter列表视图..我自定义列表视图与上面的链接相同(PullToRefreshListView,位于库中)
cursor = db.getAllRecordsOfTransaction(search);
if (cursor.getCount() > 0) {
llNoTransaction.setVisibility(LinearLayout.GONE);
cursor.moveToFirst();
scAdapter = new SimpleCursorAdapter(getActivity()
.getApplicationContext(),
R.layout.list_notransactions, cursor,
new String[] { "business_name",
"total_amount",
"status",
"purchase_datetime" },
new int[] { R.id.buissness_nm,
R.id.total_amt,
R.id.status,
R.id.purchase_date }, 0);
scAdapter.setViewBinder(new SimpleCursorAdapter.ViewBinder() {
@Override
public boolean setViewValue(View view,
Cursor cursor, int column) {
if (column == 4) {
if (cursor.getString(4)
.equals("1")) {
TextView stat = (TextView) view
.findViewById(R.id.status);
stat.setText("Approved");
} else {
TextView stat = (TextView) view
.findViewById(R.id.status);
stat.setText("DisApproved");
}
return true;
} else if (column == 5) {
TextView amt = (TextView) view
.findViewById(R.id.total_amt);
amt.setText("$"
+ cursor.getString(4));
return true;
}
return false;
}
});
System.out.println("scAdapter linearlayout visible");
listDisply.setAdapter(scAdapter);
listDisply.setSelection(1);
答案 0 :(得分:0)
你确定你的上面的代码是相互链接的,因为GetDataTask在刷新后会显示mListItems但在编辑后的代码中我看不到该列表(mListItems)。您正在获取并将值从光标设置到列表。我建议您使用BaseApadter列出绑定数据,并在向其添加新数据后调用onRefreshComplete。如果您想使用SimpleCursorAdapter,也可以在此处查看此link。希望你明白我的意思。