In android, I have a text view defined as follows:
<TextView android:id="@+id/text1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/hello_world" android:textColorHighlight="#000000" android:textIsSelectable="true" />
My goal is that after clicking 4 times, I want to start a new job. I need to do this using RXJava; this is a requirement. Or rxAndroid , rxBinding , etc.
My activity is as follows:
public class MainActivity extends Activity implements onClickListener { TextView tv; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); tv=(TextView)findViewById(R.id.text1); tv.setOnClickListener(this); } @Override public void onClick(View v) { if(v.getId() == R.id.text1){ } } }
UPDATE: but this is just the standard way to do this. With reactive rxJava API there should be a way.
So, instead of using onClicklistener with rxBinding , I read that we can do this:
RxView.clicks(tv).flatMap(tv -> { // another observable which can throw onError. return Observable.error(null); }).subscribe(object -> { Log.d("CLICK", "textview clicked", start activity); }, error -> { Log.d("CLICK", "ERROR"); });
Is there any way to use the command in rxBinding to execute it only after 4 clicks? I do not want to store a static variable or use an anonymous class and store a member variable for counting. There must be an observable method for this.
source share