我已经实现了一个listview,其中包含来自url的解析数据,我已经使用了懒惰的适配器。现在我希望列表中的conatins pull to refresh属性但我的问题是我无法找到正确的方法实现这一点,PLZ帮助
我的列表视图XML是: -
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/upBar" >
<ListView
android:id="@+id/latestList"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:cacheColorHint="#00000000"
android:listSelector="#00000000"
android:padding="7dp"
android:scrollbars="none" />
</RelativeLayout>
我的懒惰适配器是这样的: -
public class LazyAdapter extends BaseAdapter {
private Activity activity;
private ArrayList<String> movieThumbnail;
private ArrayList<String> movieText;
private static LayoutInflater inflater=null;
static File cacheDir;
ImageLoader imageloader = new ImageLoader(activity);
public LazyAdapter(Activity a, ArrayList<String> movieThumbnail, ArrayList<String> movieText) {
activity = a;
/*data=d;*/
this.movieThumbnail = movieThumbnail;
this.movieText = movieText;
inflater = (LayoutInflater)activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
public int getCount() {
return movieText.size();
}
public Object getItem(int position) {
return position;
}
public long getItemId(int position) {
return position;
}
public View getView(int position, View convertView, ViewGroup parent) {
View vi=convertView;
if(convertView==null)
vi = inflater.inflate(R.layout.listrow, null);
TextView text=(TextView)vi.findViewById(R.id.rowListTextView);
ImageView image=(ImageView)vi.findViewById(R.id.movieImage);
text.setText(movieText.get(position));
imageloader.DisplayImage(movieThumbnail.get(position), image);
return vi;
}
public void clear(){
imageloader.clearCache();
}
我正在AsyncTask中设置延迟适配器,如下所示: -
@Override protected void onPostExecute(ArrayList<HashMap<String, String>> result) {
lazyAdapter = new LazyAdapter(context, imgLinks, latestData);
listView.setAdapter(lazyAdapter);}
答案 0 :(得分:1)
这是一个很好的教程,您可以使用它来执行此操作:
答案 1 :(得分:0)
您可以使用 Pull to Refresh Views for Android 库