工作内容:自我安排
熟悉自定义控件,自定义适配器
学习分享:
试想:
把 Socket 客户端放在手机app上,这不就做成了一个聊天室了吗?
如果把聊天室的 Socket 链接到不同的IP(服务器),那不就实现了多聊天室了吗?
如果把聊天室的 布局文件 改成一个视频直播的布局方式,那 不就是一个视频直播聊天室了吗?
代码:自定义ArrayAdapter
import android.content.Context;
import android.view.LayoutInflater;
import android.view.ViewGroup;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.TextView;
import java.util.List;
/**
* 聊天室的适配器
* Created by Administrator on 2016/6/29.
*/
public class ChatRoomAdapter extends ArrayAdapter<ChatRoomClass>{
int resourceID;
public ChatRoomAdapter(Context context,int textViewResourceID,List<ChatRoomClass> list){
super(context,textViewResourceID,list);
this.resourceID = textViewResourceID;
}
@Override
public View getView(int position,View convertView,ViewGroup parent){
//获取点击的列表项
ChatRoomClass chatRoomClass = getItem(position);
View view = LayoutInflater.from(getContext()).inflate(resourceID,null);
if(convertView == null){
//这里可以做一个优化
}else{
}
TextView textView_roomName = (TextView)view.findViewById(R.id.textView_groupName_chatRoomName_item);
TextView textView_roomNum = (TextView)view.findViewById(R.id.textView_groupNum_chatRoomName_item);
textView_roomName.setText(chatRoomClass.getName());
textView_roomNum.setText(chatRoomClass.getNum());
return view;
}
}
class ChatRoomClass {
private String roomName;
private int num;
public ChatRoomClass(String roomName,int num){
this.num = num;
this.roomName = roomName;
}
public String getName(){
return this.roomName;
}
public int getNum(){
return this.num;
}
}
//下面是模仿微信的聊天窗口的一个headline
import android.app.Activity; import android.content.Context; import android.util.AttributeSet; import android.view.LayoutInflater; import android.view.View; import android.widget.ImageView; import android.widget.LinearLayout; import android.widget.TextView; /** * Created by Administrator on 2016/6/28. * 创建一个头栏控件 */ public class HeadLine_control extends LinearLayout{ private Context context; private ImageView backView; private TextView name; private ImageView detailView; public HeadLine_control(Context context,AttributeSet attr){ //调用父类的构造函数 super(context, attr); //添加头布局文件 LayoutInflater.from(context).inflate(R.layout.headline_layout,this); backView = (ImageView)findViewById(R.id.imageView_back_headline); backView.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { ((Activity)getContext()).finish(); } }); } }