Java CWAC-带阵列适配器的端部适配器

Java CWAC-带阵列适配器的端部适配器,java,android,commonsware-cwac,endlessadapter,Java,Android,Commonsware Cwac,Endlessadapter,大家都好,在过去的一周里,我一直在试图弄清楚用EndlesAdapter包装我的适配器到底意味着什么,但没有成功。我已经尝试了我有限的知识,到目前为止,我正在输掉这场战斗。我在网上读了几个例子,并阅读了endlessadapter说明,但它并没有真正起到帮助作用。谁能解释一下包装我的适配器的意义吗 我的列表视图如下: package com.bopbi.ui; import java.sql.Date; import java.text.SimpleDateFormat; import jav

大家都好,在过去的一周里,我一直在试图弄清楚用EndlesAdapter包装我的适配器到底意味着什么,但没有成功。我已经尝试了我有限的知识,到目前为止,我正在输掉这场战斗。我在网上读了几个例子,并阅读了endlessadapter说明,但它并没有真正起到帮助作用。谁能解释一下包装我的适配器的意义吗

我的列表视图如下:

package com.bopbi.ui;

import java.sql.Date;
import java.text.SimpleDateFormat;
import java.util.ArrayList;

import com.bopbi.R;
import com.bopbi.model.LocationAdapter;
import com.bopbi.model.LocationList;
import com.bopbi.model.LocationModel;
import com.bopbi.model.PullToRefreshListView.OnRefreshListener;
import com.bopbi.util.RestClient;
import com.bopbi.model.PullToRefreshListView;
import com.bopbi.util.RestClient.RequestMethod;
import com.google.android.maps.GeoPoint;
import com.google.gson.Gson;

import android.app.ActionBar;
import android.app.Activity;
import android.app.ListActivity;
import android.content.Context;
import android.location.LocationManager;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.SystemClock;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

public class ListRest extends ListActivity {


LocationManager lm;
GeoPoint userLocation;

//static String[] TITLE;
//static String[] DESCRIPTION;

ArrayList<LocationModel> locationArray = null;
LocationAdapter locationAdapter;
LocationList list;

//PullToRefreshListView lv;
TextView loadingText;

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    ActionBar actionBar = getActionBar();
    actionBar.setDisplayShowTitleEnabled(false);
  //  actionBar.show();
  //  actionBar.setDisplayShowHomeEnabled(true);

    setContentView(R.layout.activity_home);

   // lv = (PullToRefreshListView) findViewById(R.id.list);

    locationArray = new ArrayList<LocationModel>();
    locationAdapter = new LocationAdapter(ListRest.this, R.layout.dublet, locationArray);
    ((PullToRefreshListView) getListView()).onRefresh();

 //   lv.setTextFilterEnabled(true);
    setListAdapter(locationAdapter);
    //this.getListView().scrollTo(0,160);
    //this.getListView().scrollTo(0,0);
    // Set a listener to be invoked when the list should be refreshed.
    ((PullToRefreshListView) getListView()).setOnRefreshListener(new OnRefreshListener() {
        @Override
        public void onRefresh() {
            // Do work to refresh the list here.
            try {
                new LocationSync().execute("http://exposezvous.com/list.php");
            } catch(Exception e) {} 
        }
    });



        try {
            new LocationSync().execute("http://exposezvous.com/list.php");
        } catch(Exception e) {} 



}





private class LocationSync extends AsyncTask<String, Integer, LocationList> {

    @Override
    protected void onPreExecute() {

}   

    protected LocationList doInBackground(String... urls) {
        LocationList list = null;
        int count = urls.length;

        for (int i = 0; i < count; i++) {
            try {           
                // ntar diganti service
                RestClient client = new RestClient(urls[i]);

                try {
                    client.Execute(RequestMethod.GET);
                } catch (Exception e) {
                    e.printStackTrace();
                }

                String json = client.getResponse();

                list = new Gson().fromJson(json, LocationList.class);

                //
            } catch(Exception e) {}
        }
        return list;
    }

    protected void onProgressUpdate(Integer... progress) {

    }

    protected void onPostExecute(LocationList loclist) {

        // Obtain MotionEvent object
        long downTime = SystemClock.uptimeMillis();
        long eventTime = SystemClock.uptimeMillis() + 100;
        float x = 1.0f;
        float y = 10.0f;
        // List of meta states found here: developer.android.com/reference/android/view/KeyEvent.html#getMetaState()
        int metaState = 0;
        MotionEvent motionEvent = MotionEvent.obtain(
            downTime, 
            eventTime, 
            MotionEvent.ACTION_MOVE, 
            x, 
            y, 
            metaState
        );  

        for(LocationModel lm : loclist.getLocations())
       {
     locationArray.add(lm);
        }
        locationAdapter.notifyDataSetChanged();
     // Call onRefreshComplete when the list has been refreshed.

   ((PullToRefreshListView) getListView()).onRefreshComplete();
    ((PullToRefreshListView) getListView()).onTouchEvent(motionEvent);

    ((PullToRefreshListView) getListView()).setLastUpdated("Last Updated on Jan 24, 2013 8:27 PM");
    }

}
}
package com.bopbi.model;


import java.util.List;

import android.content.Context;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bopbi.R;


public class LocationAdapter extends  ArrayAdapter<LocationModel> {

int resource;
String response;
Context context;
private LayoutInflater mInflater;
private final ImageDownloader imageDownloader = new ImageDownloader();
public int count;

public LocationAdapter(Context context, int resource,
        List<LocationModel> objects) {
    super(context, resource, objects);
    this.resource = resource;
    mInflater = LayoutInflater.from(context);
}

static class ViewHolder {
    TextView username;
    ImageView image;
}

public View getView(int position, View convertView, ViewGroup parent) {
    ViewHolder holder;
    // Get the current location object
    LocationModel lm = (LocationModel) getItem(position);

    // Inflate the view
    if (convertView == null) {

        convertView = mInflater.inflate(R.layout.dublet, null);
        holder = new ViewHolder();



        holder.username = (TextView) convertView
                .findViewById(R.id.username);
        holder.image = (ImageView) convertView
                .findViewById(R.id.profilePic);

        // .findViewById(R.id.it_location_description);

        convertView.setTag(holder);

    } else {
        holder = (ViewHolder) convertView.getTag();
    }

    holder.username.setText(lm.getName());
    //String url = "http://***********/small_profile_pic_white_bigger.jpg";


    ImageDownloader.Mode mode = ImageDownloader.Mode.CORRECT;
    imageDownloader.setMode(mode);
    imageDownloader.download(lm.getImage(), holder.image);
    return convertView;
}




}
package com.bopbi.ui;
导入java.sql.Date;
导入java.text.simpleDataFormat;
导入java.util.ArrayList;
进口com.bopbi.R;
导入com.bopbi.model.LocationAdapter;
导入com.bopbi.model.LocationList;
导入com.bopbi.model.LocationModel;
导入com.bopbi.model.PullToRefreshListView.OnRefreshListener;
导入com.bopbi.util.RestClient;
导入com.bopbi.model.PullToRefreshListView;
导入com.bopbi.util.RestClient.RequestMethod;
导入com.google.android.maps.GeoPoint;
导入com.google.gson.gson;
导入android.app.ActionBar;
导入android.app.Activity;
导入android.app.ListActivity;
导入android.content.Context;
导入android.location.LocationManager;
导入android.os.AsyncTask;
导入android.os.Bundle;
导入android.os.SystemClock;
导入android.view.LayoutInflater;
导入android.view.MotionEvent;
导入android.view.view;
导入android.widget.LinearLayout;
导入android.widget.TextView;
公共类ListRest扩展了ListActivity{
位置经理lm;
地理点用户定位;
//静态字符串[]标题;
//静态字符串[]描述;
ArrayList locationArray=null;
位置适配器位置适配器;
位置列表;
//PullToRefreshListView lv;
文本视图加载文本;
创建时的公共void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
ActionBar ActionBar=getActionBar();
actionBar.setDisplayShowTitleEnabled(false);
//actionBar.show();
//actionBar.setDisplayShowHomeEnabled(真);
setContentView(R.layout.activity_home);
//lv=(PullToRefreshListView)findViewById(R.id.list);
locationArray=新的ArrayList();
locationAdapter=新的locationAdapter(ListRest.this、R.layout.dublet、locationArray);
((PullToRefreshListView)getListView()).onRefresh();
//lv.setTextFilterEnabled(真);
setListAdapter(locationAdapter);
//this.getListView().scrollTo(0160);
//this.getListView().scrollTo(0,0);
//设置要在刷新列表时调用的侦听器。
((PullToRefreshListView)getListView()).setOnRefreshListener(新的OnRefreshListener()){
@凌驾
公共void onRefresh(){
//请务必刷新此处的列表。
试一试{
新建位置同步()。执行(“http://exposezvous.com/list.php");
}捕获(例外e){}
}
});
试一试{
新建位置同步()。执行(“http://exposezvous.com/list.php");
}捕获(例外e){}
}
私有类LocationSync扩展异步任务{
@凌驾
受保护的void onPreExecute(){
}   
受保护的LocationList doInBackground(字符串…URL){
LocationList=null;
int count=url.length;
for(int i=0;i
我的自定义适配器如下所示:

package com.bopbi.ui;

import java.sql.Date;
import java.text.SimpleDateFormat;
import java.util.ArrayList;

import com.bopbi.R;
import com.bopbi.model.LocationAdapter;
import com.bopbi.model.LocationList;
import com.bopbi.model.LocationModel;
import com.bopbi.model.PullToRefreshListView.OnRefreshListener;
import com.bopbi.util.RestClient;
import com.bopbi.model.PullToRefreshListView;
import com.bopbi.util.RestClient.RequestMethod;
import com.google.android.maps.GeoPoint;
import com.google.gson.Gson;

import android.app.ActionBar;
import android.app.Activity;
import android.app.ListActivity;
import android.content.Context;
import android.location.LocationManager;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.SystemClock;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

public class ListRest extends ListActivity {


LocationManager lm;
GeoPoint userLocation;

//static String[] TITLE;
//static String[] DESCRIPTION;

ArrayList<LocationModel> locationArray = null;
LocationAdapter locationAdapter;
LocationList list;

//PullToRefreshListView lv;
TextView loadingText;

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    ActionBar actionBar = getActionBar();
    actionBar.setDisplayShowTitleEnabled(false);
  //  actionBar.show();
  //  actionBar.setDisplayShowHomeEnabled(true);

    setContentView(R.layout.activity_home);

   // lv = (PullToRefreshListView) findViewById(R.id.list);

    locationArray = new ArrayList<LocationModel>();
    locationAdapter = new LocationAdapter(ListRest.this, R.layout.dublet, locationArray);
    ((PullToRefreshListView) getListView()).onRefresh();

 //   lv.setTextFilterEnabled(true);
    setListAdapter(locationAdapter);
    //this.getListView().scrollTo(0,160);
    //this.getListView().scrollTo(0,0);
    // Set a listener to be invoked when the list should be refreshed.
    ((PullToRefreshListView) getListView()).setOnRefreshListener(new OnRefreshListener() {
        @Override
        public void onRefresh() {
            // Do work to refresh the list here.
            try {
                new LocationSync().execute("http://exposezvous.com/list.php");
            } catch(Exception e) {} 
        }
    });



        try {
            new LocationSync().execute("http://exposezvous.com/list.php");
        } catch(Exception e) {} 



}





private class LocationSync extends AsyncTask<String, Integer, LocationList> {

    @Override
    protected void onPreExecute() {

}   

    protected LocationList doInBackground(String... urls) {
        LocationList list = null;
        int count = urls.length;

        for (int i = 0; i < count; i++) {
            try {           
                // ntar diganti service
                RestClient client = new RestClient(urls[i]);

                try {
                    client.Execute(RequestMethod.GET);
                } catch (Exception e) {
                    e.printStackTrace();
                }

                String json = client.getResponse();

                list = new Gson().fromJson(json, LocationList.class);

                //
            } catch(Exception e) {}
        }
        return list;
    }

    protected void onProgressUpdate(Integer... progress) {

    }

    protected void onPostExecute(LocationList loclist) {

        // Obtain MotionEvent object
        long downTime = SystemClock.uptimeMillis();
        long eventTime = SystemClock.uptimeMillis() + 100;
        float x = 1.0f;
        float y = 10.0f;
        // List of meta states found here: developer.android.com/reference/android/view/KeyEvent.html#getMetaState()
        int metaState = 0;
        MotionEvent motionEvent = MotionEvent.obtain(
            downTime, 
            eventTime, 
            MotionEvent.ACTION_MOVE, 
            x, 
            y, 
            metaState
        );  

        for(LocationModel lm : loclist.getLocations())
       {
     locationArray.add(lm);
        }
        locationAdapter.notifyDataSetChanged();
     // Call onRefreshComplete when the list has been refreshed.

   ((PullToRefreshListView) getListView()).onRefreshComplete();
    ((PullToRefreshListView) getListView()).onTouchEvent(motionEvent);

    ((PullToRefreshListView) getListView()).setLastUpdated("Last Updated on Jan 24, 2013 8:27 PM");
    }

}
}
package com.bopbi.model;


import java.util.List;

import android.content.Context;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bopbi.R;


public class LocationAdapter extends  ArrayAdapter<LocationModel> {

int resource;
String response;
Context context;
private LayoutInflater mInflater;
private final ImageDownloader imageDownloader = new ImageDownloader();
public int count;

public LocationAdapter(Context context, int resource,
        List<LocationModel> objects) {
    super(context, resource, objects);
    this.resource = resource;
    mInflater = LayoutInflater.from(context);
}

static class ViewHolder {
    TextView username;
    ImageView image;
}

public View getView(int position, View convertView, ViewGroup parent) {
    ViewHolder holder;
    // Get the current location object
    LocationModel lm = (LocationModel) getItem(position);

    // Inflate the view
    if (convertView == null) {

        convertView = mInflater.inflate(R.layout.dublet, null);
        holder = new ViewHolder();



        holder.username = (TextView) convertView
                .findViewById(R.id.username);
        holder.image = (ImageView) convertView
                .findViewById(R.id.profilePic);

        // .findViewById(R.id.it_location_description);

        convertView.setTag(holder);

    } else {
        holder = (ViewHolder) convertView.getTag();
    }

    holder.username.setText(lm.getName());
    //String url = "http://***********/small_profile_pic_white_bigger.jpg";


    ImageDownloader.Mode mode = ImageDownloader.Mode.CORRECT;
    imageDownloader.setMode(mode);
    imageDownloader.download(lm.getImage(), holder.image);
    return convertView;
}




}
package com.bopbi.model;
导入java.util.List;
导入android.content.Context;
导入android.view.LayoutInflater;
导入android.view.view;
导入android.view.ViewGroup;
导入android.widget.ArrayAdapter;
导入android.widget.ImageView;
导入android.widget.TextView;
进口com.bopbi.R;
公共类LocationAdapter扩展了ArrayAdapter{
智力资源;
字符串响应;
语境;
私人停车场;
私有最终ImageDownloader ImageDownloader=新ImageDownloader();
公共整数计数;
公共位置适配器(上下文、int资源、,
列出对象){
超级(上下文、资源、对象);
这个资源=资源;
mInflater=LayoutInflater.from(上下文);
}
静态类视窗夹{
文本视图用户名;
图像视图图像;
}
公共视图getView(int位置、视图转换视图、视图组父视图){
视窗座;
//获取当前位置对象
LocationModel lm=(LocationModel)getItem(位置);
//夸大观点
if(convertView==null){
convertView=mInflater.充气(R.layout.dublet,nul