布局界面,这是一个图片加三个文本
适配器与填充的假数据
package com.example.connection_adapter;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import com.example.hello.R;
import android.content.Context;
import android.text.NoCopySpan.Concrete;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.View.OnClickListener;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
public class Connection_adapter extends BaseAdapter {
//对话窗口适配器
private Context context;
private LayoutInflater inflater;
private List
//假的数据进行填充
public void getData() {
list = new ArrayList
//判断是ListView界面里是否已经创建View视图,优化ListView,防止重复创建
if (convertView == null) {
view = inflater.inflate(R.layout.activity_connection, null);
holder = new ViewHolder();
holder.IV_head = (ImageView) view.findViewById(R.id.IV_head);
holder.NatName = (TextView) view.findViewById(R.id.NatName);
holder.TVContent = (TextView) view.findViewById(R.id.TVContent);
holder.Time = (TextView) view.findViewById(R.id.Time);
view.setTag(holder);
} else {
view = convertView;
holder = (ViewHolder) view.getTag();
}
//list.get(position);
//System.out.println("查看List中是否有数据::list.get(position)" + position);
holder.NatName.setText((String) list.get(position).get("NatName"));
holder.TVContent.setText((String) list.get(position).get("TVContent"));
holder.Time.setText((String) list.get(position).get("Time"));
holder.IV_head.setImageResource((Integer) list.get(position).get(
"IV_head"));
return view;
}
class ViewHolder {
ImageView IV_head;
TextView NatName, TVContent, Time;
}
}
Activit界面
package com.example.connection_adapter;
import java.util.List;
import java.util.Map;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;
import com.example.chat.Chat_Activity;
import com.example.hello.R;
//对话窗口启动
public class Conection_click extends Activity {
private ListView connection_list;
private Connection_adapter adapter;
private List> list;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_listview_connection);
connection_list = (ListView) findViewById(R.id.connection_list);
System.out.println("list的大小是" + list.size());
adapter = new Connection_adapter(Conection_click.this, list);
connection_list.setAdapter(adapter);
//item中的监听器,监听到并跳转的下个界面,
connection_list.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView> arg0, View arg1, int arg2,
long arg3) {
Intent intent = new Intent();
intent.setClass(Conection_click.this, Chat_Activity.class);
startActivity(intent);
}
});
}
}