我知道有很多类似的线程,但我已经通过他们,仍然无法找出问题。我的程序到达处理程序,但它总是返回catch消息“消息未处理”。android TextView setText不工作
我宣布TextView的private TextView chatbox;
下的onCreate我:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
setUpViews();
setUpListener();
}
其中setUpViews()片段的样子:
private void setUpViews() {
chatbox = (TextView) findViewById(R.id.chatbox);
}
处理程序:
public Handler mHandler = new Handler(Looper.getMainLooper()){
@Override
public void handleMessage(Message msg){
try{
chatbox.setText("Got it!");
}catch(Exception e){
Log.i("MYLOG", "Message was not handled.");
}
}
};
在main.xml文件中的代码片段:
<TextView
android:id="@+id/chatbox"
android:layout_width="200dp"
android:layout_height="200dp"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:textAppearance="?android:attr/textAppearanceLarge" />
你有什么异常? – Nick