package cn.buaa.myweixin; import java.util.ArrayList; import java.util.Calendar; import java.util.List; import android.app.Activity; import android.content.Intent; import android.graphics.drawable.LevelListDrawable; import android.os.Bundle; import android.text.Editable; import android.view.View; import android.view.View.OnClickListener; import android.view.WindowManager; import android.widget.Button; import android.widget.EditText; import android.widget.ListView; /** * * @author geniuseoe2012 * 更多精彩,请关注我的CSDN博客http://blog.csdn.net/geniuseoe2012 * android开发交流群:200102476 */ public class ChatActivity extends Activity implements OnClickListener{ /** Called when the activity is first created. */ private Button mBtnSend; private Button mBtnBack; private EditText mEditTextContent; private ListView mListView; private ChatMsgViewAdapter mAdapter; private List<ChatMsgEntity> mDataArrays = new ArrayList<ChatMsgEntity>(); public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.chat_xiaohei); //启动activity时不自动弹出软键盘 getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN); initView(); initData(); } public void initView() { mListView = (ListView) findViewById(R.id.listview); mBtnSend = (Button) findViewById(R.id.btn_send); mBtnSend.setOnClickListener(this); mBtnBack = (Button) findViewById(R.id.btn_back); mBtnBack.setOnClickListener(this); mEditTextContent = (EditText) findViewById(R.id.et_sendmessage); } private String[]msgArray = new String[]{"有大吗", "有!你呢?", "我也有", "那上吧", "打啊!你放大啊", "你咋不放大呢?留大抢人头那!shit!你个菜b", "2B不解释", "滚....",}; private String[]dataArray = new String[]{"2012-09-01 18:00", "2012-09-01 18:10", "2012-09-01 18:11", "2012-09-01 18:20", "2012-09-01 18:30", "2012-09-01 18:35", "2012-09-01 18:40", "2012-09-01 18:50"}; private final static int COUNT = 8; public void initData() { for(int i = 0; i < COUNT; i++) { ChatMsgEntity entity = new ChatMsgEntity(); entity.setDate(dataArray[i]); if (i % 2 == 0) { entity.setName("小黑"); entity.setMsgType(true); }else{ entity.setName("人马"); entity.setMsgType(false); } entity.setText(msgArray[i]); mDataArrays.add(entity); } mAdapter = new ChatMsgViewAdapter(this, mDataArrays); mListView.setAdapter(mAdapter); } @Override public void onClick(View v) { // TODO Auto-generated method stub switch(v.getId()) { case R.id.btn_send: send(); break; case R.id.btn_back: finish(); break; } } private void send() { String contString = mEditTextContent.getText().toString(); if (contString.length() > 0) { ChatMsgEntity entity = new ChatMsgEntity(); entity.setDate(getDate()); entity.setName("人马"); entity.setMsgType(false); entity.setText(contString); mDataArrays.add(entity); mAdapter.notifyDataSetChanged(); mEditTextContent.setText(""); mListView.setSelection(mListView.getCount() - 1); } } private String getDate() { Calendar c = Calendar.getInstance(); String year = String.valueOf(c.get(Calendar.YEAR)); String month = String.valueOf(c.get(Calendar.MONTH)); String day = String.valueOf(c.get(Calendar.DAY_OF_MONTH) + 1); String hour = String.valueOf(c.get(Calendar.HOUR_OF_DAY)); String mins = String.valueOf(c.get(Calendar.MINUTE)); StringBuffer sbBuffer = new StringBuffer(); sbBuffer.append(year + "-" + month + "-" + day + " " + hour + ":" + mins); return sbBuffer.toString(); } public void head_xiaohei(View v) { //标题栏 返回按钮 Intent intent = new Intent (ChatActivity.this,InfoXiaohei.class); startActivity(intent); } }
最近下载更多
652654393 LV4
11月18日
AI31415926 LV1
2023年5月30日
8813579 LV1
2022年6月22日
cuberbread LV6
2022年6月22日
2286417988 LV3
2022年5月24日
萌了个乖乖 LV12
2022年5月20日
刘锦峰 LV4
2022年1月2日
1632957243 LV1
2021年11月12日
球球 LV1
2021年8月28日
确实充分还oh v LV1
2021年7月14日