Reputation: 367
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" />
Upvotes: 20
Views: 54893
Reputation: 360
when the textColor is the same as View's background color ,the text also sees invisible ,so you can define a textColor to solve it
Upvotes: 1
Reputation: 869
For future reference, I had multiple fragments, one for each tab in my ViewPager. One TextView had the same id
in two fragments and that created a conflict. I didn't realize I had the same id
so everything seemed fine, no error message, but the text simply didn't change. Therefore I'd recommend using unique names for the id
.
Upvotes: 56
Reputation: 18986
In my case, I found there are a TextWatcher
and a Filter
linked to my Textview
, which both contain a logic that prevents the updating of my Textview
value.
So additionally to other solutions, you can check if your Textview
is linked to any TextWatcher
or Filter
and then trace it.
Upvotes: 3
Reputation: 31161
You haven't given us much to go on.
You should look at the exception stack trace, instead of printing a message to the console: e.printStackTrace();
But from here, if I had to guess, it looks like you're either setting the TextView's text off the main thread, or - and which appears unlikely based on what you've posted - your TextView has not been set and you have a null pointer exception.
Upvotes: 2
Reputation:
just like this is ok!
private void setUpViews() {
chatbox = (TextView) findViewById(R.id.chatbox);
chatbox.setText("Got it!");
}
Upvotes: 0
Reputation: 224
have you send a message? for example:
Message message=new Message();
message.what=1;
mHandler.sendMessage(message);
Upvotes: -1
Reputation: 8488
I hope you handler is running in UI Thread. Also try doing this: Assign your string to a variable and use that variable as it requires charsequence.
String temp = "Got it!";
chatbox.setText(temp);
Upvotes: 4