我的 TextView 上有一个onTouchListener。在接触时,我登录,Timber.i()
然后打电话给finish()
。如果在完成()之后,我再次启动我的应用程序,然后再次单击 TextView,它将记录两次,然后是 3 次,等等...
(如果我用普通的 Log.i() 替换 Timber.i() 就没有问题)
// first time
Clicked
// second time
Clicked
Clicked
// etc...
Clicked
Clicked
Clicked
木材版本:
compile 'com.jakewharton.timber:timber:4.5.1'
工作代码:
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Timber.plant(new Timber.DebugTree());
TextView tv = (TextView) findViewById(R.id.mytextview);
tv.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
Timber.i("Clicked");
finish();
return false;
}
});
}
布局 :
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.caca.test.MainActivity">
<TextView
android:id="@+id/mytextview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"/>
</android.support.constraint.ConstraintLayout>