在android中,当项目数小于可滚动项目数时,pulltorefreshlistview不工作
我从上面的链接中选取了一个例子。。当项目数量少于可滚动项目时,我无法刷新它 下面是在我的活动类中编写的代码在android中,当项目数小于可滚动项目数时,pulltorefreshlistview不工作,android,android-listview,pull-to-refresh,Android,Android Listview,Pull To Refresh,我从上面的链接中选取了一个例子。。当项目数量少于可滚动项目时,我无法刷新它 下面是在我的活动类中编写的代码 @Override public void onRefresh() { System.out.println("on refresh"); // disAll(); new GetDataTask().execute(); // listDisply.onRefreshComplete(); } private class GetDataTask ext
@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);
}
}
设置列表视图的适配器的我的代码。。我有和上面链接相同的自定义列表视图(PullToRefreshListView,位于库中)
您确定上面的代码是相互链接的吗?因为GetDataTask在刷新后会显示mListItems,但在编辑后的代码中,我看不到该列表(mListItems)。您正在获取和设置从游标到列表的值。我建议您使用BaseApadter for Your list绑定数据,并在向其中添加新数据后调用RefreshComplete。如果您想使用SimpleCorsOrAdapter,也可以在这里检查。希望你明白我的意思。如果项目数较少,列表视图将不会滚动。它应该有最少的项目滚动一个列表我知道..但我需要实现拉刷新列表视图的功能,即使项目数少于可滚动项目你可以发布你的整个代码,或者至少是您为listview设置适配器的地方。@Shrikant我已经发布了SetAdapter的代码。我引用了该链接。我在代码中更改了listview名称和适配器。。我还将pulltorefreshlistview(来自库)中的setadapter方法放在了注释中。因为我使用的是simplecursoradapter对象而不是listadapter
listDisply = (PullToRefreshListView) v.findViewById(R.id.lvList);
listDisply.setOnRefreshListener(this);
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);