朋友,
我正在使用以下教程来延迟加载列表视图
现在问题是我无法更新如果新数据出现在任何一个指导我我在做什么错误? Lazy Load Tutorial
我更改的代码
public class MainActivity extends Activity {
ListView list;
LazyAdapter adapter;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
list=(ListView)findViewById(R.id.list);
adapter=new LazyAdapter(this, mStrings,mValues);
list.setAdapter(adapter);
Button b=(Button)findViewById(R.id.button1);
b.setOnClickListener(listener);
}
@Override
public void onDestroy()
{
adapter.imageLoader.stopThread();
list.setAdapter(null);
super.onDestroy();
}
public OnClickListener listener=new OnClickListener(){
@Override
public void onClick(View v) {
adapter.imageLoader.clearCache();
ChangeData();
// adapter=new LazyAdapter(MainActivity.this, mStrings,mValues);
adapter.notifyDataSetChanged();
}
};
public void ChangeData()
{
mValues = mValues1;
mStrings = mStrings2;
}
private String[] mValues = {
"670625317/aam-logo-v3-twitter.png",
"740897825/AndroidCast-350_normal.png",
"121630227/Droid_normal.jpg",
"957149154/twitterhalf_normal.jpg"
};
private String[] mValues1 = {
"670625317/aam-logo-v3-twitter.png",
"740897825/AndroidCast-350_normal.png",
"121630227/Droid_normal.jpg",
"957149154/twitterhalf_normal.jpg",
"97470808/icon_normal.png",
"511790713/AG.png",
"956404323/androinica-avatar_normal.png",
"909231146/Android_Biz_Man_normal.png",
};
private String[] mStrings ={ "http://zef.me/wp-content/uploads/2008/02/funny-cat.jpg",
"http://www.prchurch.com/data/43_800px-Bulgaria_stub.svg.png",
"http://a3.twimg.com/profile_images/121630227/Droid_normal.jpg",
"http://a1.twimg.com/profile_images/957149154/twitterhalf_normal.jpg"};
private String[] mStrings2={
"http://zef.me/wp-content/uploads/2008/02/funny-cat.jpg",
"http://www.prchurch.com/data/43_800px-Bulgaria_stub.svg.png",
"http://a3.twimg.com/profile_images/121630227/Droid_normal.jpg",
"http://a1.twimg.com/profile_images/957149154/twitterhalf_normal.jpg",
"http://a1.twimg.com/profile_images/97470808/icon_normal.png",
"http://a3.twimg.com/profile_images/511790713/AG.png",
"http://a3.twimg.com/profile_images/956404323/androinica-avatar_normal.png",
"http://a1.twimg.com/profile_images/909231146/Android_Biz_Man_normal.png",
};
}
答案 0 :(得分:5)
可能是这样的:
public OnClickListener listener=new OnClickListener(){
@Override
public void onClick(View v) {
adapter.mValues = mValues1;
adapter.mStrings = mStrings2;
adapter.notifyDataSetChanged();
}
};
答案 1 :(得分:0)
我相信这里发生的事情是适配器的数据并没有真正改变。 您可以将这样的方法添加到适配器:
changeData(String[] d) {
data=d;
notifyDatasetChanged();
}
我认为这应该可以解决您的问题。
干杯