适配器..........
作者:互联网
package com.example.adapter;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import java.util.List;
/**
-
@Author:tiguan
-
@E-mail:
-
@Date:2019/2/21 11:02 AM
-
@Description:描述信息
*/
public class MyFragmentAdapter extends FragmentPagerAdapter {
private String[] titles;
private List list;public MyFragmentAdapter(FragmentManager fm, String[] titles, List list) {
super(fm);
this.titles = titles;
this.list = list;
}@Nullable
@Override
public CharSequence getPageTitle(int position) {
return titles[position];
}@Override
public Fragment getItem(int i) {
return list.get(i);
}@Override
public int getCount() {
return list.size();
}
}
========================================================================================
package com.example.adapter;
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.bumptech.glide.Glide;
import com.example.bean.News;
import com.example.week2demo.R;
import java.util.List;
/**
-
@Author:tiguan
-
@E-mail:
-
@Date:2019/2/21 11:27 AM
-
@Description:描述信息
*/
public class MyAdapter extends BaseAdapter {
private List list;
private Context context;public MyAdapter(List list, Context context) {
this.list = list;
this.context = context;
}@Override
public int getCount() {
return list.size();
}@Override
public Object getItem(int position) {
return list.get(position);
}@Override
public long getItemId(int position) {
return position;
}@Override
public int getItemViewType(int position) {
return position % 3;
}@Override
public int getViewTypeCount() {
return 3;
}@Override
public View getView(int position, View convertView, ViewGroup parent) {
switch (getItemViewType(position)) {
case 0:
//第一种
ViewHolder1 holder1;
if (convertView == null) {
convertView = View.inflate(context, R.layout.item_layout1, null);
holder1 = new ViewHolder1();
holder1.img_view1 = convertView.findViewById(R.id.img_view1);
holder1.text_title1 = convertView.findViewById(R.id.text_title1);
holder1.text_info1 = convertView.findViewById(R.id.text_info1);
convertView.setTag(holder1);
} else {
holder1 = (ViewHolder1) convertView.getTag();
}
holder1.text_info1.setText(list.get(position).getNews_summary());
holder1.text_title1.setText(list.get(position).getNews_title());
Glide.with(context).load(list.get(position).getPic_url()).into(holder1.img_view1);break; case 1: //第二种 ViewHolder2 holder2; if (convertView == null) { convertView = View.inflate(context, R.layout.item_layout2, null); holder2 = new ViewHolder2(); holder2.img_view2 = convertView.findViewById(R.id.img_view2); holder2.text_title2 = convertView.findViewById(R.id.text_title2); holder2.text_info2 = convertView.findViewById(R.id.text_info2); convertView.setTag(holder2); } else { holder2 = (ViewHolder2) convertView.getTag(); } holder2.text_info2.setText(list.get(position).getNews_summary()); holder2.text_title2.setText(list.get(position).getNews_title()); Glide.with(context).load(list.get(position).getPic_url()).into(holder2.img_view2); break; case 2: //第二种 ViewHolder3 holder3; if (convertView == null) { convertView = View.inflate(context, R.layout.item_layout3, null); holder3 = new ViewHolder3(); holder3.img_view3 = convertView.findViewById(R.id.img_view3); convertView.setTag(holder3); } else { holder3 = (ViewHolder3) convertView.getTag(); } Glide.with(context).load(list.get(position).getPic_url()).into(holder3.img_view3); break; } return convertView;
}
class ViewHolder1 {
private ImageView img_view1;
private TextView text_title1, text_info1;
}class ViewHolder2 {
private ImageView img_view2;
private TextView text_title2, text_info2;
}class ViewHolder3 {
private ImageView img_view3;
}
}
=====================================================================
package com.example.helper;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
/**
-
@Author:tiguan
-
@E-mail:
-
@Date:2019/2/21 11:50 AM
-
@Description:描述信息
*/
public class MyHelper extends SQLiteOpenHelper {
public MyHelper( Context contextable) {
super(contextable, “bawei.db”, null, 1);
}@Override
public void onCreate(SQLiteDatabase db) {
//创建表
db.execSQL(“create table news(title varchar(200),info varchar(500))”);
}@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {}
}
=--------------------------------------------=====
package com.example.util;
import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
/**
-
@Author:tiguan
-
@E-mail:
-
@Date:2019/2/21 11:17 AM
-
@Description:描述信息
*/
public class HttpUtil {
//判断网络
public static boolean isNetConnected(Context context) {
if (context != null) {
ConnectivityManager manager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo info = manager.getActiveNetworkInfo();
if (info != null) {
return info.isConnected();
}
}
return false;
}//请求数据
public static String getNetData(String dataUrl) {
try {
URL url = new URL(dataUrl);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod(“GET”);
int code = connection.getResponseCode();
if (code == 200) {
InputStream inputStream = connection.getInputStream();
BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
StringBuilder builder = new StringBuilder();
String str = “”;
while ((str = reader.readLine()) != null) {
builder.append(str);
}
return builder.toString();
}
} catch (Exception e) {
e.printStackTrace();
}
return “”;
}
}
标签:text,适配器,list,convertView,position,import,public,.......... 来源: https://blog.csdn.net/weixin_44293637/article/details/87924377