写三个xml文件第一个放入listview控件第二个写入所需控件,第三个也同样写入所需控件
1主Activty中
package com.example.wzqtemp; import android.os.Bundle; import android.support.v7.app.AppCompatActivity; import android.widget.ListView; import java.util.ArrayList; public class MainActivity extends AppCompatActivity { private ListView lv; private ArrayList<String> list=new ArrayList<String>(); @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); lv = (ListView) findViewById(R.id.lv); lv.setAdapter(new Mydapter(MainActivity.this,list)); for (int i=0;i<10;i++){ list.add("haha"+i); } } }2.适配器+imgloder文件
3配置imgloder类package com.example.wzqtemp; 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.ArrayList; /** * author:Created by WangZhiQiang on 2017/9/6. */ public class Mydapter extends BaseAdapter { Context context; ArrayList<String> list; String string = "http://image.tianjimedia.com/uploadImages/2012/067/N80N0GUA36N0.jpg"; public Mydapter(Context context, ArrayList<String> list) { this.context = context; this.list = list; } private final int type1 = 0; private final int type2 = 1; @Override public int getCount() { return list.size(); } @Override public Object getItem(int i) { return list.get(i); } @Override public long getItemId(int i) { return i; } @Override public int getViewTypeCount() { return 2; } @Override public int getItemViewType(int position) { if (position%2==0){ return type1; }else { return type2; } } @Override public View getView(int i, View view, ViewGroup viewGroup) { int type = getItemViewType(i); switch (type) { case type1: Holder1 holder1 = null; if (view == null) { holder1 = new Holder1(); view = view.inflate(context, R.layout.lv_ivm, null); holder1.textView = (TextView) view.findViewById(R.id.textView); holder1.textView2 = (TextView) view.findViewById(R.id.textView2); view.setTag(holder1); } else { holder1 = (Holder1) view.getTag(); } holder1.textView.setText(list.get(i)); holder1.textView2.setText(list.get(i)); break; case type2: Holder2 holder2=null; if (view==null){ holder2= new Holder2(); view= view.inflate(context, R.layout.lv_ivm2, null); holder2.textView3=(TextView) view.findViewById(R.id.textView3); holder2.textView4=(TextView) view.findViewById(R.id.textView4); holder2.imageView=(ImageView) view.findViewById(R.id.imageView); view.setTag(holder2); }else { holder2=(Holder2) view.getTag(); } holder2.textView3.setText(list.get(i)); holder2.textView4.setText(list.get(i)); ImageLoader.getInstance().displayImage(string,holder2.imageView); break; } return view; } class Holder1 { TextView textView; TextView textView2; } class Holder2 { TextView textView3; TextView textView4; ImageView imageView; } }
package com.wzq.moreitemlistviewdemo;
import android.app.Application;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.ImageLoaderConfiguration;
/**
* author:Created by WangZhiQiang on 2017-09-05.
*/
public class MApp extends Application {
@Override
public void onCreate() {
super.onCreate();
ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(this).build();
ImageLoader.getInstance().init(config);
}
}
4在清单文件中写入配置imgloder的类加上网络连接