android TextView setText not working
I know there are a lot of similar threads but I've gone through them and
still can't figure out the problem. My program reaches the Handler but it
always returns the catch exception "Message isn't handled."
I declared the TextView private TextView chatbox;
Under onCreate I have:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
setUpViews();
setUpListener();
}
where setUpViews() snippet looks like:
private void setUpViews() {
chatbox = (TextView) findViewById(R.id.chatbox);
}
Handler:
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.");
}
}
};
Snippet in main.xml file:
<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" />
No comments:
Post a Comment