云题海 - 专业文章范例文档资料分享平台

当前位置:首页 > 嵌入式课程设计之android聊天室 - 图文

嵌入式课程设计之android聊天室 - 图文

  • 62 次阅读
  • 3 次下载
  • 2025/6/19 8:35:38

课设题目:Android聊天室

private ListView itemList; private TextView filePath; private Button sendButton;

private List> adapterList; @Override

protected void onCreate(Bundle savedInstanceState) { }

// 刷新ListView

private void refreshListItems(String path) { // TODO Auto-generated method stub

// TODO Auto-generated method stub super.onCreate(savedInstanceState); setContentView(R.layout.files);

findViews();

refreshListItems(path);

filePath.setText(path);

adapterList = buildListForSimpleAdapter(path);

SimpleAdapter listAdapter = new SimpleAdapter(this, adapterList, R.layout.file_item,

}

new String[]{\, \, \},

new int[]{R.id.file_name, R.id.file_path, R.id.file_img});

itemList.setAdapter(listAdapter);

itemList.setOnItemClickListener(this); itemList.setSelection(0);

private List> buildListForSimpleAdapter(String path) {

// TODO Auto-generated method stub File nowFile = new File(path);

adapterList = new ArrayList>();

//放上根目录

Map root = new HashMap();

26

课设题目:Android聊天室

root.put(\, \);

root.put(\, R.drawable.file_root); root.put(\, \回根目录\); adapterList.add(root);

//放上父目录

Map pMap = new HashMap(); pMap.put(\, \);

pMap.put(\, R.drawable.file_parent); pMap.put(\, \上一级\); adapterList.add(pMap);

if(!nowFile.isDirectory()){ //若是当前路径对应的是文件,则返回 sendButton.setEnabled(true); //发送按钮可用 return adapterList; }

File[] files = nowFile.listFiles(); //得到path下所有文件

for(File file:files){

Map map = new HashMap();

map.put(\, file.getName()); map.put(\, file.getPath()); if(file.isDirectory()){

map.put(\, R.drawable.file_directory); }else{

map.put(\, R.drawable.file_doc);

}

adapterList.add(map); }

sendButton.setEnabled(false); //当前路径对应的是文件夹,发送按钮不可return adapterList;

}

private void findViews() {

// TODO Auto-generated method stub

itemList = (ListView) findViewById(R.id.file_detail); filePath = (TextView) findViewById(R.id.file_path); sendButton = (Button) findViewById(R.id.file_send);

sendButton.setOnClickListener(this); sendButton.setEnabled(false); //开始时不可点击,只有选中的路径是文件时才可以点击

27

课设题目:Android聊天室

}

@Override

public void onItemClick(AdapterView parent, View v, int position, long id) {

}

// TODO Auto-generated method stub

Log.i(TAG, \位置[\ + position + \上的item被点击\); if(position == 0){ //回根目录 path = \;

refreshListItems(path); goToParent();

}else if(position == 1){ //回到上一级

}else{

path = (String) adapterList.get(position).get(\); refreshListItems(path); }

private void goToParent() { }

@Override

public void onClick(View v) {

// TODO Auto-generated method stub }

@Override

28

// TODO Auto-generated method stub File file = new File(path);

File pFile = file.getParentFile(); //得到父文件 if(pFile == null){

Toast.makeText(this, \当前路径已经是根目录,不存在上一级\, Toast.LENGTH_SHORT).show(); refreshListItems(path); }else{

path = pFile.getAbsolutePath(); refreshListItems(path); }

Intent intent = new Intent();

intent.putExtra(\, path); setResult(RESULT_OK, intent); finish();

课设题目:Android聊天室

public void processMessage(Message msg) { // TODO Auto-generated method stub }

}

2、NetTcpFileSendThread类 /**

* Tcp发送文件线程,实现文件发送的主要代码 * @author 钟玉文 *

* 2012/7/3 */

public class NetTcpFileSendThread implements Runnable{

private final static String TAG = \; private String[] filePathArray; //保存发送文件路径的数组

public static ServerSocket server;

private Socket socket;

private byte[] readBuffer = new byte[1024];

public NetTcpFileSendThread(String[] filePathArray){ this.filePathArray = filePathArray;

try {

server = new ServerSocket(IpMessageConst.PORT); } catch (IOException e) { // TODO Auto-generated catch block

e.printStackTrace();

Log.e(TAG, \监听tcp端口失败\); }

}

@Override

public void run() { // TODO Auto-generated method stub

for(int i = 0; i < filePathArray.length; i ++){ try {

socket = server.accept();

Log.i(TAG, \与

IP为 29

\ +

  • 收藏
  • 违规举报
  • 版权认领
下载文档10.00 元 加入VIP免费下载
推荐下载
本文作者:...

共分享92篇相关文档

文档简介:

课设题目:Android聊天室 private ListView itemList; private TextView filePath; private Button sendButton; private List adapterList; @Override protected void onCreate(Bundle savedInstanceState) { } // 刷新ListView private void refreshListItems(String path) { // TODO Auto-generated method stub // TOD

× 游客快捷下载通道(下载后可以自由复制和排版)
单篇付费下载
限时特价:10 元/份 原价:20元
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信:fanwen365 QQ:370150219
Copyright © 云题海 All Rights Reserved. 苏ICP备16052595号-3 网站地图 客服QQ:370150219 邮箱:370150219@qq.com