基本信息
源码名称:android 模仿QQ聊天气泡 入门级示例源码
源码大小:1.38M
文件格式:.zip
开发语言:Java
更新时间:2016-08-10
友情提示:(无需注册或充值,赞助后即可获取资源下载链接)
嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):813200300
本次赞助数额为: 2 元×
微信扫码支付:2 元
×
请留下您的邮箱,我们将在2小时内将文件发到您的邮箱
源码介绍
package com.study.androidtest; import java.util.ArrayList; import android.app.Activity; import android.os.Bundle; import android.view.Menu; import android.view.MenuItem; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.EditText; import android.widget.ListView; import android.widget.Spinner; import android.widget.TextView; import com.qqtest.adapter.MsgAdapter; import com.test.model.MsgInfo; public class MainActivity extends Activity { ListView lvMsg; Spinner spaMsgFrom; EditText edtTxtMsg; Button btnSend; ArrayList<MsgInfo> mArray; MsgAdapter mAdapter; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); lvMsg=(ListView)findViewById(R.id.lv_msg); spaMsgFrom=(Spinner)findViewById(R.id.spn_msg_from); edtTxtMsg=(EditText)findViewById(R.id.editTxt_msg); btnSend=(Button)findViewById(R.id.btn_send); mArray=new ArrayList<MsgInfo>(); mArray.add(new MsgInfo("你好","我",R.drawable.head_4)); mArray.add(new MsgInfo("我们的十年在哪里呢?","我",R.drawable.head_4)); mAdapter=new MsgAdapter(MainActivity.this,mArray); lvMsg.setAdapter(mAdapter); btnSend.setOnClickListener(new OnClickListener(){ @Override public void onClick(View v) { TextView tv=(TextView)spaMsgFrom.getSelectedView(); String strName=tv.getText().toString(); String strMsg=edtTxtMsg.getText().toString(); edtTxtMsg.getText().clear(); int iHead; if(strName.equals("静静")){ iHead=R.drawable.head_1; }else if(strName.equals("妹子")){ iHead=R.drawable.head_2; }else if(strName.equals("科比")){ iHead=R.drawable.head_3; }else{ iHead=R.drawable.head_4; } mArray.add(new MsgInfo(strMsg,strName,iHead)); mAdapter.notifyDataSetChanged(); } }); } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.main, menu); return true; } @Override public boolean onOptionsItemSelected(MenuItem item) { // Handle action bar item clicks here. The action bar will // automatically handle clicks on the Home/Up button, so long // as you specify a parent activity in AndroidManifest.xml. int id = item.getItemId(); if (id == R.id.action_settings) { return true; } return super.onOptionsItemSelected(item); } }