Java 带自定义单元格的PullToRefresh listView Android

Java 带自定义单元格的PullToRefresh listView Android,java,android,listview,Java,Android,Listview,我使用了这个图书馆: 工作很好,但是在ListView中很简单(我在cell android模式中说的很简单) 我戴着一个Adpter,放在我的自定义列表视图中,以显示带有图像、标题和描述的单元格 我与adpter的班级: public class extends Main_podcast ListActivity implements {OnItemClickListener private Bitmap pathImgSmal; / ** Called When the activ

我使用了这个图书馆:

工作很好,但是在ListView中很简单(我在cell android模式中说的很简单)

我戴着一个Adpter,放在我的自定义列表视图中,以显示带有图像、标题和描述的单元格

我与adpter的班级:

public class extends Main_podcast ListActivity implements {OnItemClickListener

private Bitmap pathImgSmal;
    / ** Called When the activity is first created. * /
    @ Override
    public void onCreate (Bundle savedInstanceState) {
        super.onCreate (savedInstanceState);

        Mybundle bundle = new Bundle ();
    mybundle.putString ("podcastnumber", "0");

        / / Check for connection and starts downloading the XML
    Connected conected Boolean = (this);
        if (conected == true) {
    DoInBackground new (). execute ();
    Else {}
    new AlertDialog.Builder (Main_podcast.this)
    . SetTitle ("Alert!")
. SetMessage ("Unable to connect to the Internet," +
"Check your network or try again later.")
. SetNeutralButton ("OK"
new DialogInterface.OnClickListener () {
public void onClick (DialogInterface dialog,
int which) {}
}). Show ();
    }

    }


    / / Method calls the XML Parser
    public void do_update ()
    {
    PodcastParser.parse ();
    }

    / / Method that populates the list view with XML parameters
    public void populate_listview ()
    {
        List <Itens> podcastList <Itens> = new ArrayList ();

        for (int i = 0; i <arraysPodcast.PodcastTitle.length; i + +) {
            end item Items = new Items ();
        item.setTitle (arraysPodcast.PodcastTitle [i]);
        item.setData (arraysPodcast.PodcastData [i]);


        item.setImage (arraysPodcast.ArrayIMGPodcast [i]);
        podcastList.add (item);

        }

        setListAdapter (new PodcastAdapter (this, podcastList));
        ListView shot getListView = ();

        shot.setOnItemClickListener ((OnItemClickListener) this);

    }

    public void onItemClick (AdapterView <?> arg0, View v, int position, long id) {
    / / Start the Activity podcast regarding your number from the list
    Myintent intent = new Intent ("com.example.player.PODCAST");
    Mybundle bundle = new Bundle ();
    mybundle.putInt ("podcastnumber" position);
    myintent.putExtras (mybundle);

    startActivity (myintent);

}


    private class extends DoInBackground AsyncTask <Void, Void, Void>
                                 implements DialogInterface.OnCancelListener
    {
        ProgressDialog private dialog;

        protected void OnPreExecute ()
        {
        dialog = ProgressDialog.show (Main_podcast.this, "", "Loading Podcasts ...", true);
        }

        protected void doInBackground (Void. unused ..)
        {
        do_update ();
        return null;
        }

        OnPostExecute protected void (Void unused)
        {
        dialog.dismiss ();
        populate_listview ();
        }

        public void onCancel (DialogInterface dialog)
        {
        cancel (true);
        dialog.dismiss ();
        }
    }

    public static boolean Connected (Context context) {
        try {
            = ConnectivityManager cm (ConnectivityManager)
            context.getSystemService (Context.CONNECTIVITY_SERVICE);
            LogSync String = null;
            LogToUserTitle String = null;
            if (cm.getNetworkInfo (ConnectivityManager.TYPE_MOBILE). isConnected ()) {
                    LogSync + = "\ nConectado 3G Internet";
                    LogToUserTitle + = "Connected to 3G Internet";

                    return true;
            } Else if (cm.getNetworkInfo (ConnectivityManager.TYPE_WIFI). IsConnected ()) {
                    LogSync + = "\ nConectado WIFI Internet";
                    LogToUserTitle + = "Connected to Wireless Internet";
                    return true;
            Else {}
                    LogSync + = "\ nYou have internet connection";
                    LogToUserTitle + = "Do not have an internet connection";

                    return false;
            }
        } Catch (Exception e) {
                return false;
        }
    }


} / / Class
public类扩展了Main\u播客ListActivity实现了{OnItemClickListener
私有位图路径;
/**首次创建活动时调用。*/
@凌驾
创建时的公共void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
Mybundle=新bundle();
mybundle.putString(“podcastnumber”,“0”);
//检查连接并开始下载XML
连通连通布尔=(此);
如果(连接==真){
doinbackgroundnew().execute();
Else{}
新建AlertDialog.Builder(Main_podcast.this)
.SetTitle(“警报!”)
.SetMessage(“无法连接到Internet,”+
“请检查您的网络或稍后再试。”)
.SetNeutralButton(“确定”
新建DialogInterface.OnClickListener(){
公共void onClick(对话框接口对话框,
int其中){}
}).Show();
}
}
//Method调用XML解析器
公共void do_update()
{
PodcastParser.parse();
}
//Method,该方法使用XML参数填充列表视图
public void填充\u列表视图()
{
List-podcastList=newarraylist();
对于(int i=0;i而言,决定如下:

public class PullToRefreshActivity extends ListActivity implements OnItemClickListener {
    private LinkedList<String> mListItems;
    private List<Itens> podcastList;
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.pull_to_refresh);
        // Set a listener to be invoked when the list should be refreshed.
        // ======================================================
        Bundle mybundle = new Bundle();
        mybundle.putString("podcastnumber", "0");

        //verifica se há conexao e inicia download do XML
        Boolean conected = Conectado(this);
        if(conected == true){
            new DoInBackground().execute();
        }else{
            new AlertDialog.Builder(PullToRefreshActivity.this)
            .setTitle("Alerta!")
            .setMessage("Não foi possível estabelecer uma conexão com a Internet," +
                    "verifique sua rede ou tente novamente mais tarde.")
            .setNeutralButton("OK",
        new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog,
             int which) {}
      }).show();
        }

     // ======================================================


        ((PullToRefreshListView) getListView()).setOnRefreshListener(new OnRefreshListener() {
            @Override
            public void onRefresh() {
                // Do work to refresh the list here.
                new DoInBackground().execute();
            }
        });


    }

    // ==================================================================
    public void do_update() 
    {
        PodcastParser.parse();
    }

    //metodo que preenche a list view com parametros do XML
    public void populate_listview()
    {  

        podcastList = new ArrayList<Itens>();

        for (int i = 0; i < arraysPodcast.PodcastTitle.length; i++) {
            final Itens item = new Itens();
            item.setTitle(arraysPodcast.PodcastTitle[i]);
            item.setData(arraysPodcast.PodcastData[i]);


            item.setImage(arraysPodcast.ArrayIMGPodcast[i]);
            podcastList.add(item);

        }  

        setListAdapter(new PodcastAdapter(this, podcastList));

        ((PullToRefreshListView) getListView()).setOnItemClickListener((OnItemClickListener) this);
    }

    public void onItemClick(AdapterView<?> arg0, View v, int position, long id) {
        //Inicia Activity da podcast referente a seu numero da lista
        Intent myintent = new Intent("com.example.player.PODCAST");
        Bundle mybundle = new Bundle();
        mybundle.putInt("podcastnumber", (position-1));
        Log.e("posicao na lista",""+position);
        myintent.putExtras(mybundle);

        startActivity(myintent);

    }


    private class DoInBackground extends AsyncTask<Void, Void, Void>
                                 implements DialogInterface.OnCancelListener
    {
        private ProgressDialog dialog;

        protected void onPreExecute() 
        {

            dialog = ProgressDialog.show(PullToRefreshActivity.this, "", "Carregando Podcasts...", true);
        }

        protected Void doInBackground(Void... unused) 
        { 
            PodcastAdapter.topBar=true;
            do_update(); 
            return null; 
        }

        protected void onPostExecute(Void unused) 
        { 
            ((PullToRefreshListView) getListView()).onRefreshComplete();
            dialog.dismiss(); 
            populate_listview();
        }

        public void onCancel(DialogInterface dialog) 
        { 
            cancel(true); 
            dialog.dismiss(); 
        }
    }

    public static boolean Conectado(Context context) {
        try {
            ConnectivityManager cm = (ConnectivityManager)
            context.getSystemService(Context.CONNECTIVITY_SERVICE);
            String LogSync = null;
            String LogToUserTitle = null;
            if (cm.getNetworkInfo(ConnectivityManager.TYPE_MOBILE).isConnected()) {
                    LogSync += "\nConectado a Internet 3G ";
                    LogToUserTitle += "Conectado a Internet 3G ";

                    return true;
            } else if(cm.getNetworkInfo(ConnectivityManager.TYPE_WIFI).isConnected()){
                    LogSync += "\nConectado a Internet WIFI ";
                    LogToUserTitle += "Conectado a Internet WIFI ";
                    return true;
            } else {
                    LogSync += "\nNão possui conexão com a internet ";
                    LogToUserTitle += "Não possui conexão com a internet ";

                    return false;
            }
        } catch (Exception e) {
                return false;
        }
    }

}
公共类PullToRefreshActivity扩展ListActivity实现OnItemClickListener{
私有链接列表;
私人名单播客名单;
/**在首次创建活动时调用*/
@凌驾
创建时的公共void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.pull\u到\u刷新);
//设置要在刷新列表时调用的侦听器。
// ======================================================
Bundle mybundle=新Bundle();
mybundle.putString(“podcastnumber”,“0”);
//verifica seáconexao e inicia下载XML
布尔连接=连接(this);
如果(连接==真){
新建DoInBackground().execute();
}否则{
新建AlertDialog.Builder(PullToRefreshActivity.this)
.setTitle(“Alerta!”)
.setMessage(“网络公司”+
“验证是否需要进行重大更新。”)
.setNeutralButton(“确定”,
新建DialogInterface.OnClickListener(){
公共void onClick(对话框接口对话框,
int其中){}
}).show();
}
// ======================================================
((PullToRefreshListView)getListView()).setOnRefreshListener(新的OnRefreshListener()){
@凌驾
公共void onRefresh(){
//请务必刷新此处的列表。
新建DoInBackground().execute();
}
});
}
// ==================================================================
public void do_update()
{
parse();
}
//metodo que预先设置列表视图com参数do XML
public void populate_listview()
{  
podcastList=newarraylist();
for(int i=0;i