首页 技术 正文
技术 2022年11月6日
0 收藏 514 点赞 949 浏览 4704 个字

@XStreamAlias(“result”)
public class Myresult {

@XStreamImplicit(itemFieldName=”item”)

package com.example.yuekao1;

import java.util.ArrayList;
import java.util.List;
import com.baidu.net.Network;
import com.baidu.vo1.Good;
import com.baidu.vo1.Mydata;
import com.google.gson.Gson;
import com.handmark.pulltorefresh.library.PullToRefreshBase;
import com.handmark.pulltorefresh.library.PullToRefreshBase.OnRefreshListener2;
import com.handmark.pulltorefresh.library.PullToRefreshGridView;
import android.os.AsyncTask;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.text.format.DateUtils;
import android.view.KeyEvent;
import android.widget.GridView;
import android.widget.Toast;

public class Show extends Activity implements OnRefreshListener2<GridView> {

private String name;
    private PullToRefreshGridView gv;
    private List<Mydata> data;
    private Base1 b1;
    List<Mydata> list = new ArrayList<Mydata>();
    private Exit exit;

protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

setContentView(R.layout.activity_show);
        gv = (PullToRefreshGridView) findViewById(R.id.gv);
        new Asy().execute();
        gv.setOnRefreshListener(this);
        exit = new Exit();
        Intent in = getIntent();
        name = in.getStringExtra(“id”);
    }

class Asy extends AsyncTask<String, Integer, String> {

protected String doInBackground(String… params) {
            String s1 = Network
                    .getjson(“http://apis.juhe.cn/goodbook/query?key=9d6ef8c31647a206e05fcaff70527182&dtype=gson&rn=10&pn=10&catalog_id=”
                            + name);
            return s1;
        }

protected void onPostExecute(String result) {

Gson g = new Gson();
            Good json = g.fromJson(result, Good.class);
        if (fromJson.getResult() != null
                    && fromJson.getResult().getData() != null) {

List<Mydata> data = fromJson.getResult().getData();
                list = data;
                b2 = new Base2(list, Show.this);
                gv.onRefreshComplete();
                gv.setAdapter(b2);
                initIndicator();
            }

}
    }

class Asynt extends AsyncTask<String, Integer, String> {

protected String doInBackground(String… params) {
            String s1 = Network
                    .getjson(“http://apis.juhe.cn/goodbook/query?key=9d6ef8c31647a206e05fcaff70527182&dtype=gson&rn=10&pn=10&catalog_id=”
                            + name);
            return s1;
        }

protected void onPostExecute(String result) {

Gson g = new Gson();
            Good json = g.fromJson(result, Good.class);
            List<Mydata> data2 = json.getResult().getData();
            list.addAll(data2);
            b1.notifyDataSetChanged();
            gv.onRefreshComplete();
            initIndicator();

}
    }

public void onPullDownToRefresh(PullToRefreshBase<GridView> refreshView) {
        new Asy().execute();
    }

public void onPullUpToRefresh(PullToRefreshBase<GridView> refreshView) {
        new Asynt().execute();
    }

private void initIndicator() {
        String label = DateUtils.formatDateTime(getApplicationContext(),
                System.currentTimeMillis(), DateUtils.FORMAT_SHOW_TIME
                        | DateUtils.FORMAT_SHOW_DATE
                        | DateUtils.FORMAT_ABBREV_ALL);
        gv.getLoadingLayoutProxy().setLastUpdatedLabel(label);
    }

public boolean onKeyDown(int keyCode, KeyEvent event) {
        if (keyCode == KeyEvent.KEYCODE_BACK) {
            pressAgainExit();
            return true;
        }

return super.onKeyDown(keyCode, event);
    }

private void pressAgainExit() {
        if (exit.isExit()) {
            finish();
        } else {
            Toast.makeText(getApplicationContext(), “再按一次退出程序”,
                    Toast.LENGTH_SHORT).show();
            exit.doExitInOneSecond();
        }
    }
}

package com.example.yuekao1;

import android.os.Handler;
import android.os.HandlerThread;

public class Exit {
    private boolean isExit = false;
    private Runnable task = new Runnable() {
        @Override
        public void run() {
            isExit = false;
        }
    };

public void doExitInOneSecond() {
        isExit = true;
        HandlerThread thread = new HandlerThread(“doTask”);
        thread.start();
        new Handler(thread.getLooper()).postDelayed(task, 1000);
    }

public boolean isExit() {
        return isExit;
    }

public void setExit(boolean isExit) {
        this.isExit = isExit;
    }
}

<com.handmark.pulltorefresh.library.PullToRefreshGridView
        xmlns:ptr=”http://schemas.android.com/apk/res-auto”
        android:id=”@+id/gv”
        android:layout_width=”fill_parent”
        android:layout_height=”fill_parent”
        android:cacheColorHint=”#00000000″
        android:divider=”#19000000″
        android:dividerHeight=”4dp”
        android:fadingEdge=”none”
        android:fastScrollEnabled=”false”
        android:footerDividersEnabled=”false”
        android:headerDividersEnabled=”false”
        android:numColumns=”3″
        android:smoothScrollbar=”true”
        ptr:ptrMode=”both” >
    </com.handmark.pulltorefresh.library.PullToRefreshGridView>

in.putExtra(“id”, item.get(arg2).getId());

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:8,996
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,510
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,353
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,137
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,770
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,848