android中Handler线程中handleMessage(android.os.Message msg)函数不执行,小弟想做一个类似微信的语音 35
部分代码:一Handlerhan=newHandler(){publicvoidhandleMessage(android.os.Messagemsg){Toast.ma...
部分代码:
一
Handler han = new Handler() {
public void handleMessage(android.os.Message msg) {
Toast.makeText(MessageActivity.this, "jinlail", Toast.LENGTH_LONG).show();
LinearLayout client = new LinearLayout(MessageActivity.this);
TextView t = new TextView(MessageActivity.this);
t.setText(msg.getData().getString("username") + "说:");
Button button = new Button(MessageActivity.this);
button.setText("播放");
final String filepath = msg.getData().getString("filename");
button.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
MediaPlayer mediaPlayer = new MediaPlayer();
if (mediaPlayer.isPlaying()) {
mediaPlayer.reset();
}
try {
mediaPlayer.setDataSource("/sdcard/" + filepath);
mediaPlayer.prepare();
mediaPlayer.start();
} catch (Exception e) {
// TODO: handle exception
}
}
});
client.setOrientation(LinearLayout.HORIZONTAL);
client.addView(t);
client.addView(button);
line.addView(client);
};
};
二
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.setContentView(R.layout.message);
new Thread() {
public void run() {
UDPServer.message=MessageActivity.this;
try {
UDPServer.openServer();
} catch (Exception e) {
e.printStackTrace();
}
};
}.start();
}
三
Message msg = new Message();
Bundle b3 = new Bundle();b3.putString("username", s.split(",")[0]);
b3.putString("filename", s.split(",")[1]);
msg.setData(b3); message.han.sendMessage(msg); 展开
一
Handler han = new Handler() {
public void handleMessage(android.os.Message msg) {
Toast.makeText(MessageActivity.this, "jinlail", Toast.LENGTH_LONG).show();
LinearLayout client = new LinearLayout(MessageActivity.this);
TextView t = new TextView(MessageActivity.this);
t.setText(msg.getData().getString("username") + "说:");
Button button = new Button(MessageActivity.this);
button.setText("播放");
final String filepath = msg.getData().getString("filename");
button.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
MediaPlayer mediaPlayer = new MediaPlayer();
if (mediaPlayer.isPlaying()) {
mediaPlayer.reset();
}
try {
mediaPlayer.setDataSource("/sdcard/" + filepath);
mediaPlayer.prepare();
mediaPlayer.start();
} catch (Exception e) {
// TODO: handle exception
}
}
});
client.setOrientation(LinearLayout.HORIZONTAL);
client.addView(t);
client.addView(button);
line.addView(client);
};
};
二
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.setContentView(R.layout.message);
new Thread() {
public void run() {
UDPServer.message=MessageActivity.this;
try {
UDPServer.openServer();
} catch (Exception e) {
e.printStackTrace();
}
};
}.start();
}
三
Message msg = new Message();
Bundle b3 = new Bundle();b3.putString("username", s.split(",")[0]);
b3.putString("filename", s.split(",")[1]);
msg.setData(b3); message.han.sendMessage(msg); 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询