从Android Market获取灵感,我实现了一个Endless List,当我们到达List的末尾时,它会从服务器加载更多数据.
现在,我需要实现进度条和"正在加载..."文本,如图所示
从中获取灵感的示例代码将非常棒.
我想在Android ListView组件上实现无限滚动,当滚动到列表中的最后一个元素时,它会将新项添加到listview的底部.
我已经创建了一个ListView,它由查询返回的数据填充.
它有效,但在LogCat中我收到了消息:
Cursor Window: Window is full: requested allocation 444 bytes, free space 363 bytes, window size 2097152 bytes
Run Code Online (Sandbox Code Playgroud)
它使用几分钟来加载/可视化ListView.
我的查询返回大约3700行String/Int/Double,每行包含30列; 没有图像或特定数据类型
这条消息究竟意味着什么,我该如何避免呢?
您可以通过更改此光标窗口来提高性能吗?
我的Android应用程序通过使用在用户PC上生成并传输到设备的SQLite数据库来工作.这一切都有效,但我没有预料到拥有大量数据的用户数量.在这些情况下,UI在等待获取数据时非常缓慢.
我已经尝试了一些技巧,我"确定"会加快速度,但似乎没有任何明显的效果.我的查询几乎都非常简单,通常是WHERE子句的单个"col = val"和列中的INTEGER数据.所以我对查询做不了多少.
最新的,我不是SQL专家,无论如何都是在PC上使用"CREATE INDEX"命令,认为这些索引用于加速数据库搜索.索引显着增加了数据库文件的大小,所以我很惊讶它似乎对我的应用程序的速度没有任何影响!在没有索引的情况下花费8秒钟填充的屏幕仍然需要大约8秒钟.我希望能把事情减少至少一半.
我现在想知道的是,如果Android上的SQLite实现完全使用数据库索引,或者我只是通过生成它们来浪费空间.谁能回答这个问题?
还有什么其他的东西可以尝试加快访问速度?
(对于它的价值,在绝对的基础上,用户没有什么可抱怨的.到目前为止,我的最坏情况用户的数据产生了630,000条记录(15个表),所以只有这么多可能!)
Doug Gordon GHCS Systems
我有一个有大量下载的应用程序,我收到了很多这个错误:
16783 AndroidRuntime E java.lang.IndexOutOfBoundsException: Invalid index 0, size is 0
16783 AndroidRuntime E at java.util.ArrayList.throwIndexOutOfBoundsException(ArrayList.java:257)
16783 AndroidRuntime E at java.util.ArrayList.get(ArrayList.java:311)
16783 AndroidRuntime E at android.widget.HeaderViewListAdapter.isEnabled(HeaderViewListAdapter.java:16
4)
16783 AndroidRuntime E at android.widget.ListView.dispatchDrawWithExcessScroll_Default(ListView.java:3
288)
16783 AndroidRuntime E at android.widget.ListView.dispatchDraw(ListView.java:3029)
16783 AndroidRuntime E at android.view.View.draw(View.java:6743)
16783 AndroidRuntime E at android.widget.AbsListView.draw(AbsListView.java:2549)
16783 AndroidRuntime E at android.view.ViewGroup.drawChild(ViewGroup.java:1640)
16783 AndroidRuntime E at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1367)
16783 AndroidRuntime E at android.view.View.draw(View.java:6743)
16783 AndroidRuntime E at android.view.ViewGroup.drawChild(ViewGroup.java:1640)
16783 AndroidRuntime E at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1367)
16783 AndroidRuntime E at android.view.ViewGroup.drawChild(ViewGroup.java:1638)
16783 AndroidRuntime …Run Code Online (Sandbox Code Playgroud) java android listview indexoutofboundsexception commonsware-cwac
我有一个列表视图,显示图像和文本.我希望一次显示8个listview行,从服务器下载数据.当用户滚动列表视图时,我需要从服务器下载更多数据并在列表视图中显示这些项目.我使用AsyncTask从服务器下载数据.
@Override
protected Void doInBackground(Void... params) {
getData();// get data first time. 8 data items.
return null;
}
@Override
protected void onPostExecute(Void result) {
super.onPostExecute(result);
pd.dismiss();
lv= (ListView) findViewById(R.id.lvn);
yt = new YouTubeAdapter(Youtube.this,msg,title,thumb);
lv.setAdapter(yt);
lv.setOnScrollListener(new EndLessScroll());
}
Run Code Online (Sandbox Code Playgroud)
获取数据代码
public void getData()
{
HttpClient httpclient = new DefaultHttpClient();
httpclient.getParams().setParameter(CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP_1_1);
HttpGet request = new HttpGet("http://gdata.youtube.com/feeds/api/users/mbbangalore/uploads?v=2&alt=jsonc");
try
{
HttpResponse response = httpclient.execute(request);
HttpEntity resEntity = response.getEntity();
String _response=EntityUtils.toString(resEntity); // content will be consume only once
JSONObject json = new JSONObject(_response);
jsonArray = …Run Code Online (Sandbox Code Playgroud) 我有一个包含100个项目的列表视图,我想显示前10个项目,点击下一个按钮我必须显示下一个10即.从11到20,我有获得前10项的代码
public int getCount() {
return 10;
}
Run Code Online (Sandbox Code Playgroud)
但如何单独获得下一个10项等等.任何的想法
目前,我正在使用AsyncTask来处理Http连接并以JSON格式检索数据.
加载所有数据是微不足道的,但它消耗了太多时间,所以我决定使用LIMIT OFFSET(mysql)一次切换到加载10个项目.
接下来,我onScroll为列表视图设置事件,以便AsyncTask每次用户滚动时创建一个新事件.但是,从我读到的,AsyncTask存储在一次限制5个线程的线程池中,所以我不确定这是一个正确的方法.我是客户/服务器应用程序的新手,所以我可以在这个问题上给我一个建议吗?任何相关的文章,文档将不胜感激.
我正在开发一个应用程序,我需要显示一些列表视图控件.我只是OnScrollListener在我的活动中实现,以便监视我的listview内容,但是当我为我的活动设置布局时,它不会调用onScroll事件.如果我评论该块然后它调用它就好了.我该如何解决这个问题?
package com.Threadtest;
import com.Threadtest.main.myRunnable;
import android.app.Activity;
import android.app.ListActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AbsListView;
import android.widget.BaseAdapter;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.AbsListView.OnScrollListener;
public class TestList extends ListActivity implements OnScrollListener {
Aleph0 adapter = new Aleph0();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.test);
ListView listview=(ListView)findViewById(android.R.id.list);
listview.setAdapter(adapter);
/*setListAdapter(adapter);
getListView().setOnScrollListener(this);*/
}
public void onScroll(AbsListView view,
int firstVisible, final int visibleCount, int totalCount) {
Log.i("TestList", "firstVisible="+firstVisible+" visibleCount="+visibleCount+" totalCount="+totalCount);
boolean loadMore = /* maybe add a padding …Run Code Online (Sandbox Code Playgroud) 我想要一个代码来使ScrollView节目具有无穷无尽的滚动一遍又一遍的相同图像.
这对于布局非常好,我想知道将它添加到ScrollView无限滚动所需的代码是什么.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" >
<HorizontalScrollView
android:id="@+id/horizontalScrollView1"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >
<ImageView
android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_launcher" />
<ImageView
android:id="@+id/imageView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_launcher" />
<ImageView
android:id="@+id/imageView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_launcher" />
<ImageView
android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_launcher" />
<ImageView
android:id="@+id/imageView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_launcher" />
<ImageView
android:id="@+id/imageView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_launcher" />
<ImageView
android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_launcher" />
<ImageView
android:id="@+id/imageView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_launcher" />
<ImageView
android:id="@+id/imageView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_launcher" …Run Code Online (Sandbox Code Playgroud)