失眠网,内容丰富有趣,生活中的好帮手!
失眠网 > android聊天界面对话气泡_android 模仿QQ聊天气泡 入门级示例源码

android聊天界面对话气泡_android 模仿QQ聊天气泡 入门级示例源码

时间:2024-02-21 17:45:45

相关推荐

android聊天界面对话气泡_android 模仿QQ聊天气泡 入门级示例源码

【实例简介】

【实例截图】

【核心代码】

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 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();

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);

}

}

如果觉得《android聊天界面对话气泡_android 模仿QQ聊天气泡 入门级示例源码》对你有帮助,请点赞、收藏,并留下你的观点哦!

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。