Skip to content

Commit

Permalink
优化一下代码显示顺序
Browse files Browse the repository at this point in the history
  • Loading branch information
880634 committed Nov 2, 2018
1 parent c556532 commit cb41b24
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
> 已投入公司项目多时,没有任何毛病,可胜任任何需求,[点击此处下载Demo](https://raw.githubusercontent.com/getActivity/ToastUtils/master/ToastUtils.apk)
> 想了解实现原理的可以点击此链接查看ToastUtils源码:[ToastUtils](https://github.com/getActivity/ToastUtils/blob/master/library/src/main/java/com/hjq/toast/ToastUtils.java)
> 想了解实现原理的可以点击此链接查看:[XToast](https://github.com/getActivity/ToastUtils/blob/master/library/src/main/java/com/hjq/toast/XToast.java)[ToastUtils](https://github.com/getActivity/ToastUtils/blob/master/library/src/main/java/com/hjq/toast/ToastUtils.java) 源码
![](ToastUtils.gif)

Expand Down
13 changes: 7 additions & 6 deletions library/src/main/java/com/hjq/toast/XToast.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ final class XToast extends Toast implements Runnable {
private Handler mHandler = new Handler(Looper.getMainLooper()); // 吐司处理消息线程

private TextView mTextView; // 吐司消息View
private CharSequence mText; // 吐司显示的文本
private CharSequence mContent; // 吐司显示的文本

XToast(Context context) {
super(context);
}

@Override
public final void setView(View view) {
public void setView(View view) {
super.setView(view);
mTextView = ((TextView) view.findViewById(R.id.toast_main_text_view_id));
if (mTextView != null) {
Expand All @@ -43,9 +43,9 @@ public final void setView(View view) {
}

@Override
public final void setText(CharSequence s) {
public void setText(CharSequence s) {
// 记录本次吐司欲显示的文本
mText = s;
mContent = s;
}

@Override
Expand All @@ -62,16 +62,17 @@ public void show() {
@Override
public void run() {
// 设置吐司文本
mTextView.setText(mText);
mTextView.setText(mContent);
// 显示吐司
super.show();
}

@Override
public void cancel() {
super.cancel();
// 移除之前显示吐司的任务
mHandler.removeCallbacks(this);
// 取消显示
super.cancel();
}

/**
Expand Down

0 comments on commit cb41b24

Please sign in to comment.