Yuekao

技术精选:从前端到后端的全面探索
本文深入探讨了从前端开发到后端开发的各项技术,涵盖了HTML、CSS、JavaScript等基础技能,以及PHP、Java、Python等高级语言的应用。同时,文章还涉及了大数据开发、游戏开发、移动开发等多个领域的前沿技术,旨在为读者提供全面的技术视野。
  1 public class Fragment01 extends Fragment implements IXListViewListener{
  2     private XListView xListView;
  3     
  4     private String JSON="http://www.oschina.net/action/api/news_list?pageIndex=1";
  5     
  6     private List<News> lists = new ArrayList<News>();
  7     int i=1;
  8     
  9     MyAdapter m;
 10     @Override
 11     public View onCreateView(LayoutInflater inflater,
 12         @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
 13                 View view = LayoutInflater.from(getActivity()).inflate(R.layout.fragment_xlistview, null);
 14     
 15                 xListView = (XListView) view.findViewById(R.id.xListView);
 16                 xListView.setPullLoadEnable(true);
 17                 xListView.setPullRefreshEnable(true);
 18                 xListView.setXListViewListener(this);
 19                 
 20                 
 21         
 22                 
 23     
 24                 init();
 25                 return view;
 26 }
 27     
 28 
 29     private void init() {
 30         HttpUtils hu = new HttpUtils();
 31         hu.send(HttpMethod.GET, JSON+i++, new RequestCallBack<String>() {
 32 
 33             @Override
 34             public void onFailure(HttpException arg0, String arg1) {
 35                 // TODO Auto-generated method stub
 36                 
 37             }
 38 
 39             @Override
 40             public void onSuccess(ResponseInfo<String> arg0) {
 41                 String str = arg0.result;
 42                 XStream xs = new XStream();
 43                 xs.processAnnotations(Mydata.class);
 44                 Mydata data = (Mydata) xs.fromXML(str);
 45                 List<News> list = data.getNewslist().getNews();
 46                 lists = list;
 47                 m = new MyAdapter(getActivity(), lists);
 48                 xListView.setAdapter(m);
 49                 
 50             }
 51         });
 52     }
 53 
 54 
 55     @Override
 56     public void onRefresh() {
 57         init();
 58         onLoad();
 59         
 60     }
 61     private void onLoad() {
 62         //停止刷新、加载
 63         xListView.stopRefresh();
 64         xListView.stopLoadMore();
 65         // 设置日期格式
 66         SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
 67         // 获取当前系统时间
 68         String nowTime = df.format(new Date(System.currentTimeMillis()));
 69         // 释放时提示正在刷新时的当前时间
 70         xListView.setRefreshTime(nowTime);
 71         
 72     }
 73 
 74 
 75 
 76     @Override
 77     public void onLoadMore() {
 78         HttpUtils hu = new HttpUtils();
 79         hu.send(HttpMethod.GET, JSON+i++, new RequestCallBack<String>() {
 80 
 81             @Override
 82             public void onFailure(HttpException arg0, String arg1) {
 83                 // TODO Auto-generated method stub
 84                 
 85             }
 86 
 87             @Override
 88             public void onSuccess(ResponseInfo<String> arg0) {
 89                 String str = arg0.result;
 90                 XStream xs = new XStream();
 91                 xs.processAnnotations(Mydata.class);
 92                 Mydata data = (Mydata) xs.fromXML(str);
 93                 List<News> list = data.getNewslist().getNews();
 94                 lists.addAll(lists);
 95                 m.notifyDataSetChanged();
 96                 
 97                 
 98             }
 99         });
100         onLoad();
101     }
102 }
Fragment01
 1 public class Fragment02 extends Fragment implements IXListViewListener{
 2     private XListView xListView;
 3     
 4     private String JSON="http://www.oschina.net/action/api/news_list?pageIndex=2";
 5     
 6     private List<News> lists = new ArrayList<News>();
 7     int i=1;
 8     
 9     MyAdapter m;
10     @Override
11     public View onCreateView(LayoutInflater inflater,
12         @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
13                 View view = LayoutInflater.from(getActivity()).inflate(R.layout.fragment_xlistview, null);
14     
15                 xListView = (XListView) view.findViewById(R.id.xListView);
16                 xListView.setPullLoadEnable(true);
17                 xListView.setPullRefreshEnable(true);
18                 xListView.setXListViewListener(this);
19     
20                 init();
21                 return view;
22 }
23     
24 
25     private void init() {
26         HttpUtils hu = new HttpUtils();
27         hu.send(HttpMethod.GET, JSON+i++, new RequestCallBack<String>() {
28 
29             @Override
30             public void onFailure(HttpException arg0, String arg1) {
31                 // TODO Auto-generated method stub
32                 
33             }
34 
35             @Override
36             public void onSuccess(ResponseInfo<String> arg0) {
37                 String str = arg0.result;
38                 XStream xs = new XStream();
39                 xs.processAnnotations(Mydata.class);
40                 Mydata data = (Mydata) xs.fromXML(str);
41                 List<News> list = data.getNewslist().getNews();
42                 lists = list;
43                 m = new MyAdapter(getActivity(), lists);
44                 xListView.setAdapter(m);
45                 
46             }
47         });
48     }
49 
50 
51     @Override
52     public void onRefresh() {
53         init();
54         onLoad();
55         
56     }
57     private void onLoad() {
58         //停止刷新、加载
59         xListView.stopRefresh();
60         xListView.stopLoadMore();
61         // 设置日期格式
62         SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
63         // 获取当前系统时间
64         String nowTime = df.format(new Date(System.currentTimeMillis()));
65         // 释放时提示正在刷新时的当前时间
66         xListView.setRefreshTime(nowTime);
67         
68     }
69 
70 
71 
72     @Override
73     public void onLoadMore() {
74         HttpUtils hu = new HttpUtils();
75         hu.send(HttpMethod.GET, JSON+i++, new RequestCallBack<String>() {
76 
77             @Override
78             public void onFailure(HttpException arg0, String arg1) {
79                 // TODO Auto-generated method stub
80                 
81             }
82 
83             @Override
84             public void onSuccess(ResponseInfo<String> arg0) {
85                 String str = arg0.result;
86                 XStream xs = new XStream();
87                 xs.processAnnotations(Mydata.class);
88                 Mydata data = (Mydata) xs.fromXML(str);
89                 List<News> list = data.getNewslist().getNews();
90                 lists.addAll(lists);
91                 m.notifyDataSetChanged();
92                 
93                 
94             }
95         });
96         
97     }
98 }
Fragment02
 1 public class Fragment03 extends Fragment implements IXListViewListener{
 2 private XListView xListView;
 3     
 4     private String JSON="http://www.oschina.net/action/api/blog_list?pageIndex=";
 5     
 6     private List<Myblog> lists = new ArrayList<Myblog>();
 7     int i=1;
 8     
 9     MyListAd mm;
10     @Override
11     public View onCreateView(LayoutInflater inflater,
12             @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
13         View view = LayoutInflater.from(getActivity()).inflate(R.layout.fragment_xlistview, null);
14         
15         xListView = (XListView) view.findViewById(R.id.xListView);
16         xListView.setPullLoadEnable(true);
17         xListView.setPullRefreshEnable(true);
18         xListView.setXListViewListener(this);
19 
20         init();
21         return view;
22     }
23     private void init() {
24         HttpUtils hu = new HttpUtils();
25         hu.send(HttpMethod.GET, JSON+i++, new RequestCallBack<String>() {
26 
27             @Override
28             public void onFailure(HttpException arg0, String arg1) {
29                 // TODO Auto-generated method stub
30                 
31             }
32 
33             @Override
34             public void onSuccess(ResponseInfo<String> arg0) {
35                 String str = arg0.result;
36                 XStream xs = new XStream();
37                 xs.processAnnotations(MyObj.class);
38                 MyObj obj = (MyObj) xs.fromXML(str);
39                 List<Myblog> list = obj.getBlogs().getBlog();
40                 lists = list;
41                 mm = new MyListAd(getActivity(), lists);
42                 xListView.setAdapter(mm);
43             }
44         });
45         
46     }
47     @Override
48     public void onRefresh() {
49         init();
50         onLoad();
51         
52     }
53     private void onLoad() {
54         //停止刷新、加载
55         xListView.stopRefresh();
56         xListView.stopLoadMore();
57         // 设置日期格式
58         SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
59         // 获取当前系统时间
60         String nowTime = df.format(new Date(System.currentTimeMillis()));
61         // 释放时提示正在刷新时的当前时间
62         xListView.setRefreshTime(nowTime);
63         
64     }
65     @Override
66     public void onLoadMore() {
67         HttpUtils hu = new HttpUtils();
68         hu.send(HttpMethod.GET, JSON+i++, new RequestCallBack<String>() {
69 
70             @Override
71             public void onFailure(HttpException arg0, String arg1) {
72                 // TODO Auto-generated method stub
73                 
74             }
75 
76             @Override
77             public void onSuccess(ResponseInfo<String> arg0) {
78                 String str = arg0.result;
79                 XStream xs = new XStream();
80                 xs.processAnnotations(MyObj.class);
81                 MyObj obj = (MyObj) xs.fromXML(str);
82                 List<Myblog> list = obj.getBlogs().getBlog();
83                 lists.addAll(lists);
84                 mm.notifyDataSetChanged();
85             }
86         });
87     }
88 }
Fragment03
  1 public class MainActivity extends ActionBarActivity implements OnClickListener {
  2 
  3     private ViewPager vp;
  4     private List<Fragment> fragmentlist;
  5     private RadioButton bt1;
  6     private RadioButton bt2;
  7     private RadioButton bt3;
  8     private RadioButton bt4;
  9 
 10     @Override
 11     protected void onCreate(Bundle savedInstanceState) {
 12         super.onCreate(savedInstanceState);
 13         setContentView(R.layout.activity_main);
 14         
 15         vp = (ViewPager) findViewById(R.id.vp);
 16         
 17         init();
 18         initfragmnet();
 19         
 20         
 21         FragmentManager fm = getSupportFragmentManager();
 22         vp.setCurrentItem(0);
 23         vp.setAdapter(new FragmentPagerAdapter(fm) {
 24             
 25             @Override
 26             public int getCount() {
 27                 // TODO Auto-generated method stub
 28                 return fragmentlist.size();
 29             }
 30             
 31             @Override
 32             public Fragment getItem(int arg0) {
 33                 // TODO Auto-generated method stub
 34                 return fragmentlist.get(arg0);
 35             }
 36         });
 37         vp.setOnPageChangeListener(new OnPageChangeListener() {
 38             
 39             @Override
 40             public void onPageSelected(int arg0) {
 41                 switch (arg0) {
 42                 case 0:
 43                     bt1.setTextColor(Color.RED);
 44                     bt2.setTextColor(Color.BLACK);
 45                     bt3.setTextColor(Color.BLACK);
 46                     bt4.setTextColor(Color.BLACK);
 47                     break;
 48                 case 1:
 49                     bt1.setTextColor(Color.BLACK);
 50                     bt2.setTextColor(Color.RED);
 51                     bt3.setTextColor(Color.BLACK);
 52                     bt4.setTextColor(Color.BLACK);
 53                     break;
 54                 case 2:
 55                     bt1.setTextColor(Color.BLACK);
 56                     bt2.setTextColor(Color.BLACK);
 57                     bt3.setTextColor(Color.RED);
 58                     bt4.setTextColor(Color.BLACK);
 59                     break;
 60                 case 3:
 61                     bt1.setTextColor(Color.BLACK);
 62                     bt2.setTextColor(Color.BLACK);
 63                     bt3.setTextColor(Color.BLACK);
 64                     bt4.setTextColor(Color.RED);
 65                     break;
 66                 }
 67                 
 68             }
 69             
 70             @Override
 71             public void onPageScrolled(int arg0, float arg1, int arg2) {
 72                 // TODO Auto-generated method stub
 73                 
 74             }
 75             
 76             @Override
 77             public void onPageScrollStateChanged(int arg0) {
 78                 // TODO Auto-generated method stub
 79                 
 80             }
 81         });
 82     }
 83 
 84     private void initfragmnet() {
 85         fragmentlist = new ArrayList<Fragment>();
 86         Fragment01 fm1 = new Fragment01();
 87         Fragment02 fm2 = new Fragment02();
 88         Fragment03 fm3 = new Fragment03();
 89         Fragment04 fm4 = new Fragment04();
 90         fragmentlist.add(fm1);
 91         fragmentlist.add(fm2);
 92         fragmentlist.add(fm3);
 93         fragmentlist.add(fm4);
 94         
 95     }
 96 
 97     private void init() {
 98         
 99         bt1 = (RadioButton) findViewById(R.id.but1);
100         bt2 = (RadioButton) findViewById(R.id.but2);
101         bt3 = (RadioButton) findViewById(R.id.but3);
102         bt4 = (RadioButton) findViewById(R.id.but4);
103         
104         
105         bt1.setOnClickListener(this);
106         bt2.setOnClickListener(this);
107         bt3.setOnClickListener(this);
108         bt4.setOnClickListener(this);
109         
110     }
111 
112     @Override
113     public void onClick(View v) {
114         switch (v.getId()) {
115         case R.id.but1:
116             vp.setCurrentItem(0);
117             break;
118         case R.id.but2:
119             vp.setCurrentItem(1);
120             break;
121         case R.id.but3:
122             vp.setCurrentItem(2);
123             break;
124         case R.id.but4:
125             vp.setCurrentItem(3);
126             break;
127 
128         default:
129             break;
130         }
131         
132     }
133 
134     
135 }
MainActivity
 1 public class MyAdapter extends BaseAdapter{
 2 
 3     Context context;
 4     List<News> list;
 5 
 6 
 7     public MyAdapter(Context context, List<News> list) {
 8         super();
 9         this.context = context;
10         this.list = list;
11     }
12 
13     @Override
14     public int getCount() {
15         // TODO Auto-generated method stub
16         return list.size();
17     }
18 
19     @Override
20     public Object getItem(int position) {
21         // TODO Auto-generated method stub
22         return null;
23     }
24 
25     @Override
26     public long getItemId(int position) {
27         // TODO Auto-generated method stub
28         return 0;
29     }
30 
31     @Override
32     public View getView(int position, View convertView, ViewGroup parent) {
33         View view;
34         VH vh;
35         if (convertView==null) {
36             view = View.inflate(context, R.layout.listview_item, null);
37             vh = new VH();
38             vh.tv1 = (TextView) view.findViewById(R.id.text_title);
39             vh.tv2 = (TextView) view.findViewById(R.id.text_sub);
40             vh.tv3 = (TextView) view.findViewById(R.id.text_tt);
41             view.setTag(vh);
42         }else{
43             view = convertView;
44             vh = (VH) view.getTag();
45         }
46         vh.tv1.setText(list.get(position).getTitle());
47         vh.tv2.setText(list.get(position).getBody());
48         vh.tv3.setText(list.get(position).getAuthor()+"    "+list.get(position).getPubDate()+"   "+list.get(position).getCommentCount());
49         return view;
50     }
51 
52 }
53 class VH{
54     TextView tv1,tv2,tv3;
55 }
MyAdapter
 1 public class Myapp extends Application{
 2     
 3     @Override
 4     public void onCreate() {
 5         // TODO Auto-generated method stub
 6         super.onCreate();
 7         
 8         ImageLoaderConfiguration com = ImageLoaderConfiguration.createDefault(this);
 9         ImageLoader.getInstance().init(com);
10     }
11 
12 }
MyApp
 1 public class MyListAd extends BaseAdapter{
 2 
 3     
 4     Context context;
 5     List<Myblog> list;
 6     
 7     public MyListAd(Context context, List<Myblog> list) {
 8         super();
 9         this.context = context;
10         this.list = list;
11     }
12 
13     @Override
14     public int getCount() {
15         // TODO Auto-generated method stub
16         return list.size();
17     }
18 
19     @Override
20     public Object getItem(int position) {
21         // TODO Auto-generated method stub
22         return null;
23     }
24 
25     @Override
26     public long getItemId(int position) {
27         // TODO Auto-generated method stub
28         return 0;
29     }
30 
31     @Override
32     public View getView(int position, View convertView, ViewGroup parent) {
33         View view;
34         final VHolder vh;
35         if (convertView==null) {
36             view = View.inflate(context, R.layout.item, null);
37             vh = new VHolder();
38             vh.im = (ImageView) view.findViewById(R.id.img);
39             vh.tv1 = (TextView) view.findViewById(R.id.title);
40             vh.tv2 = (TextView) view.findViewById(R.id.body);
41             vh.tv3 = (TextView) view.findViewById(R.id.authorname);
42             
43             view.setTag(vh);
44         }else{
45             view = convertView;
46             vh = (VHolder) view.getTag();
47         }
48         vh.tv1.setText(list.get(position).getTitle());
49         vh.tv2.setText(list.get(position).getBody());
50         vh.tv3.setText(list.get(position).getAuthorname());
51         ImageSize is=new ImageSize(100,100);
52         ImageLoader.getInstance().loadImage(list.get(position).getUrl(),is, new SimpleImageLoadingListener(){
53             @Override
54             public void onLoadingComplete(String imageUri, View view,
55                     Bitmap loadedImage) {
56                 // TODO Auto-generated method stub
57                 super.onLoadingComplete(imageUri, view, loadedImage);
58                 vh.im.setImageBitmap(loadedImage);
59             }
60         });
61         return view;
62     }
63 
64 }
65 
66 class VHolder{
67     TextView tv1,tv2,tv3;
68     ImageView im;
69 }
MyListAd
 1 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
 2     xmlns:tools="http://schemas.android.com/tools"
 3     android:layout_width="match_parent"
 4     android:layout_height="match_parent"
 5   android:orientation="vertical"
 6     tools:context="com.example.xml.MainActivity" >
 7 
 8   
 9 
10   <RadioGroup
11         android:layout_width="fill_parent"
12         android:layout_height="0dp"
13         android:layout_weight="1"
14         android:gravity="bottom"
15         android:orientation="horizontal"
16        >
17        <RadioButton 
18            android:id="@+id/but1"
19            android:layout_width="0dp"
20            android:layout_height="wrap_content"
21            android:button="@null"
22            android:layout_weight="1"
23            android:gravity="center_horizontal"
24            android:text="资讯"
25            >
26            </RadioButton>
27        <RadioButton 
28            android:id="@+id/but2"
29            android:layout_width="0dp"
30            android:layout_height="wrap_content"
31            android:gravity="center_horizontal"
32            android:button="@null"
33             android:layout_weight="1"
34            android:text="资讯"
35            />
36        <RadioButton 
37            android:id="@+id/but3"
38            android:layout_width="0dp"
39            android:layout_height="wrap_content"
40            android:gravity="center_horizontal"
41            android:button="@null"
42             android:layout_weight="1"
43            android:text="资讯"
44            />
45        <RadioButton 
46            android:id="@+id/but4"
47            android:layout_width="0dp"
48            android:layout_height="wrap_content"
49            android:gravity="center_horizontal"
50             android:layout_weight="1"
51             android:button="@null"
52            android:text="资讯"
53            />
54     </RadioGroup>
55     
56        
57         
58 
59     
60     <android.support.v4.view.ViewPager
61            android:id="@+id/vp"
62            android:layout_width="fill_parent"
63            android:layout_height="0dp"
64            android:layout_weight="12"
65         ></android.support.v4.view.ViewPager>
66 </LinearLayout>
activity_main.xml
 1 <?xml version="1.0" encoding="utf-8"?>
 2 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
 3     android:layout_width="match_parent"
 4     android:layout_height="match_parent" >
 5     <com.example.xlist.XListView
 6              android:id="@+id/xListView"
 7             android:layout_width="fill_parent"
 8             android:layout_height="fill_parent"
 9             android:cacheColorHint="#00000000" >
10         </com.example.xlist.XListView>
11 
12 </RelativeLayout>
fragment_xlistview.xml
 1 <?xml version="1.0" encoding="utf-8"?>
 2 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
 3     android:layout_width="match_parent"
 4     android:layout_height="match_parent" >
 5 
 6     <WebView
 7         android:id="@+id/webview"
 8         android:layout_width="match_parent"
 9         android:layout_height="676dp" />
10     <Button
11         android:id="@+id/button1"
12         android:layout_width="match_parent"
13         android:layout_height="wrap_content"
14         android:layout_alignParentBottom="true"
15         android:layout_alignParentRight="true"
16         android:text="点击分享" />
17 
18 
19 </RelativeLayout>
info
 1 <?xml version="1.0" encoding="utf-8"?>
 2 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
 3     android:layout_width="match_parent"
 4     android:layout_height="match_parent" >
 5     
 6     
 7     <ImageView 
 8         android:id="@+id/img"
 9         android:layout_width="100dp"
10         android:layout_height="100dp"
11         android:src="@drawable/ic_launcher"/>
12 
13     <TextView
14         android:id="@+id/title"
15         android:layout_width="wrap_content"
16         android:layout_height="wrap_content"
17         android:layout_alignParentTop="true"
18         android:layout_marginLeft="25dp"
19         android:layout_toRightOf="@+id/img"
20         android:text="TextView" />
21 
22     <TextView
23         android:id="@+id/authorname"
24         android:layout_width="wrap_content"
25         android:layout_height="wrap_content"
26         android:layout_alignBottom="@+id/body"
27         android:layout_marginLeft="26dp"
28         android:layout_toRightOf="@+id/title"
29         android:text="TextView" />
30 
31     <TextView
32         android:id="@+id/body"
33         android:layout_width="wrap_content"
34         android:layout_height="wrap_content"
35         android:layout_alignBottom="@+id/img"
36         android:layout_alignLeft="@+id/title"
37         android:text="body" />
38 
39 </RelativeLayout>
item
 1 <?xml version="1.0" encoding="utf-8"?>
 2 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
 3     android:layout_width="match_parent"
 4     android:layout_height="match_parent" >
 5 
 6     <TextView
 7         android:id="@+id/text_title"
 8         android:layout_width="wrap_content"
 9         android:layout_height="wrap_content"
10         android:layout_alignParentLeft="true"
11         android:layout_alignParentTop="true"
12         android:layout_marginLeft="30dp"
13         android:layout_marginTop="16dp"
14         android:text="TextView" />
15 
16     <TextView
17         android:id="@+id/text_sub"
18         android:layout_width="wrap_content"
19         android:layout_height="wrap_content"
20         android:layout_alignLeft="@+id/text_title"
21         android:layout_below="@+id/text_title"
22         android:text="TextView" />
23 
24     <TextView
25         android:id="@+id/text_tt"
26         android:layout_width="wrap_content"
27         android:layout_height="wrap_content"
28         android:layout_alignLeft="@+id/text_sub"
29         android:layout_below="@+id/text_sub"
30         android:text="TextView" />
31 
32 </RelativeLayout>
listView_item

 

转载于:https://www.cnblogs.com/zle-mr/p/5356691.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值