标签:encoder color getc instance google gson ... str proguard
package com.example.lianxi4; import android.os.AsyncTask; import android.os.Bundle; import android.support.v7.app.AppCompatActivity; import android.view.View; import android.widget.ImageView; import com.bumptech.glide.Glide; import com.google.gson.Gson; import com.stx.xhb.xbanner.XBanner; import java.io.InputStream; import java.io.UnsupportedEncodingException; import java.net.HttpURLConnection; import java.net.URL; import java.net.URLEncoder; import java.util.ArrayList; import java.util.List; import me.maxwin.view.XListView; public class MainActivity extends AppCompatActivity implements XListView.IXListViewListener{ private XListView xlv; private int pageIndex=1; private boolean flag; private Myadapter adapter; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); XBanner banner= (XBanner) findViewById(R.id.banner_1); xlv= (XListView) findViewById(R.id.xlist); xlv.setPullLoadEnable(true); xlv.setXListViewListener(this); try { getWORKdATA("http://apis.juhe.cn/cook/query.php?menu="+ URLEncoder.encode("红烧肉","utf-8") +"&key=6787f0fab124bcf9149a5fec0aba7a86&pn="+pageIndex+"&rn=10"); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } final List<String> imgesUrl = new ArrayList<>(); imgesUrl.add("http://img3.fengniao.com/forum/attachpics/913/114/36502745.jpg"); imgesUrl.add("http://imageprocess.yitos.net/images/public/20160910/99381473502384338.jpg"); imgesUrl.add("http://imageprocess.yitos.net/images/public/20160910/77991473496077677.jpg"); imgesUrl.add("http://imageprocess.yitos.net/images/public/20160906/1291473163104906.jpg"); //添加广告数据 banner.setData(imgesUrl); banner.setmAdapter(new XBanner.XBannerAdapter() { @Override public void loadBanner(XBanner banner, View view, int position) { Glide.with(MainActivity.this).load(imgesUrl.get(position)).into((ImageView) view); } }); } private void getWORKdATA(String url){ new AsyncTask<String, Void, String>() { @Override protected void onPostExecute(String s) { super.onPostExecute(s); if (s==null){ return; } Gson gson=new Gson(); Meinfo meinfo = gson.fromJson(s, Meinfo.class); List<Meinfo.ResultBean.DataBean> list=meinfo.getResult().getData(); if (adapter==null){ adapter=new Myadapter(MainActivity.this,list); xlv.setAdapter(adapter); }else{ adapter.loadMoer(list,flag); } } @Override protected String doInBackground(String... strings) { try { URL url=new URL(strings[0]); HttpURLConnection connection = (HttpURLConnection) url.openConnection(); connection.setRequestMethod("GET"); connection.setReadTimeout(5000); connection.setConnectTimeout(5000); int code = connection.getResponseCode(); if (code==200){ InputStream inputStream = connection.getInputStream(); return Stools.getWorkNew(inputStream); } } catch (Exception e) { e.printStackTrace(); } return null; } }.execute(url); } @Override public void onRefresh() { flag=false; ++pageIndex; try { getWORKdATA("http://apis.juhe.cn/cook/query.php?menu="+ URLEncoder.encode("红烧肉","utf-8") +"&key=6787f0fab124bcf9149a5fec0aba7a86&pn="+pageIndex+"&rn=10"); xlv.stopRefresh(); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } } @Override public void onLoadMore() { flag=true; ++pageIndex; try { getWORKdATA("http://apis.juhe.cn/cook/query.php?menu="+ URLEncoder.encode("红烧肉","utf-8") +"&key=6787f0fab124bcf9149a5fec0aba7a86&pn="+pageIndex+"&rn=10"); xlv.stopLoadMore(); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } } }
//下一个类
package com.example.lianxi4; import android.content.Context; import android.view.View; import android.view.ViewGroup; import android.widget.BaseAdapter; import android.widget.ImageView; import android.widget.TextView; import com.nostra13.universalimageloader.core.ImageLoader; import java.util.List; /** * Created by 悻 on 2017/8/24. */ public class Myadapter extends BaseAdapter{ private Context context; List<Meinfo.ResultBean.DataBean> list; private static final int TYPE_1=0; private static final int TYPE_2=1; public Myadapter(Context context, List<Meinfo.ResultBean.DataBean> list) { this.context = context; this.list = list; } public void loadMoer(List<Meinfo.ResultBean.DataBean> lists,boolean flag){ for (Meinfo.ResultBean.DataBean dataBean: lists){ if (flag){ list.add(dataBean); }else{ list.add(0,dataBean); } notifyDataSetChanged(); } } @Override public int getCount() { return list!=null?list.size():0; } @Override public Object getItem(int i) { return list.get(i); } @Override public long getItemId(int i) { return i; } @Override public int getItemViewType(int position) { if (position%2==0){ return TYPE_1; }else{ return TYPE_2; } } @Override public int getViewTypeCount() { return 2; } @Override public View getView(int i, View view, ViewGroup viewGroup) { int type=getItemViewType(i); switch (type){ case TYPE_1: { view=View.inflate(context,R.layout.item,null); TextView tv1=(TextView) view.findViewById(R.id.txt); ImageView imv1=(ImageView) view.findViewById(R.id.imv1); tv1.setText(list.get(i).getTags()); ImageLoader.getInstance().displayImage(list.get(i).getAlbums().get(0),imv1); } break; case TYPE_2: { view=View.inflate(context,R.layout.item2,null); TextView tv1=(TextView) view.findViewById(R.id.tv11); tv1.setText(list.get(i).getTags()); } break; } return view; } }
*/**
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context="com.example.lianxi4.MainActivity"> <com.stx.xhb.xbanner.XBanner xmlns:app="http://schemas.android.com/apk/res-auto" android:id="@+id/banner_1" android:layout_width="match_parent" android:layout_height="180dp" app:pointsPosition="CENTER" app:AutoPlayTime="3000" app:pointsContainerBackground="#44aaaaaa" /> <me.maxwin.view.XListView android:layout_width="match_parent" android:layout_height="match_parent" android:id="@+id/xlist" android:layout_below="@+id/banner_1" /> </RelativeLayout>
/****
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="horizontal" > <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/imv1" android:src="@mipmap/ic_launcher" android:layout_gravity="center_vertical" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="adasd" android:layout_gravity="center_vertical" android:id="@+id/txt" /> </LinearLayout>
///*****
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/tv11" android:text="asdasd" android:layout_gravity="center_vertical" /> </LinearLayout>
/****
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.lianxi4">
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
<application android:allowBackup="true" android:icon="@mipmap/ic_launcher"
android:name=".Myappar"
android:label="@string/app_name" android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true" android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
/*//*/*/*/*/*
apply plugin: ‘com.android.application‘
android {
compileSdkVersion 26
buildToolsVersion "26.0.1"
defaultConfig {
applicationId "com.example.lianxi4"
minSdkVersion 26
targetSdkVersion 26
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile(‘proguard-android.txt‘), ‘proguard-rules.pro‘
}
}
}
dependencies {
compile fileTree(include: [‘*.jar‘], dir: ‘libs‘)
androidTestCompile(‘com.android.support.test.espresso:espresso-core:2.2.2‘, {
exclude group: ‘com.android.support‘, module: ‘support-annotations‘
})
compile ‘com.android.support:appcompat-v7:26.+‘
compile ‘com.xhb:xbanner:1.0.0‘
compile ‘com.github.andyoom:xlistview:v1.0.1‘
compile ‘com.android.support.constraint:constraint-layout:1.0.2‘
testCompile ‘junit:junit:4.12‘
compile ‘com.github.bumptech.glide:glide:4.0.0‘
compile ‘com.google.code.gson:gson:2.8.1‘
compile ‘com.nostra13.universalimageloader:universal-image-loader:1.9.5‘
}
标签:encoder color getc instance google gson ... str proguard
原文地址:http://www.cnblogs.com/SLXN/p/7426650.html