GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — feat: wiring up button tap with logs · pakoito/Android-RxJava@b26a227

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • app/src/main
    • java/com/morihacky/android/rxjava
      • DemoAccumulateEventFragment.java
    • res
      • layout
        • fragment_accumulate.xml
        • item_log.xml
      • values
        • strings.xml
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎app/src/main/java/com/morihacky/android/rxjava/DemoAccumulateEventFragment.java‎

Copy file name to clipboardExpand all lines: app/src/main/java/com/morihacky/android/rxjava/DemoAccumulateEventFragment.java
+48Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,32 @@
11
package com.morihacky.android.rxjava;
22

3+
import android.content.Context;
34
import android.os.Bundle;
45
import android.support.annotation.Nullable;
56
import android.support.v4.app.Fragment;
67
import android.view.LayoutInflater;
78
import android.view.View;
89
import android.view.ViewGroup;
10+
import android.widget.ArrayAdapter;
11+
import android.widget.ListView;
912

1013
import com.morihacky.android.rxjava.app.R;
1114

15+
import java.util.ArrayList;
16+
import java.util.List;
17+
1218
import butterknife.ButterKnife;
19+
import butterknife.InjectView;
20+
import butterknife.OnClick;
1321

1422
public class DemoAccumulateEventFragment
1523
extends Fragment {
1624

25+
@InjectView(R.id.accumulated_event_list) ListView _logsListView;
26+
27+
private LogAdapter _adapter;
28+
private List<String> _logs;
29+
1730
@Override
1831
public View onCreateView(LayoutInflater inflater,
1932
@Nullable ViewGroup container,
@@ -22,4 +35,39 @@ public View onCreateView(LayoutInflater inflater,
2235
ButterKnife.inject(this, layout);
2336
return layout;
2437
}
38+
39+
@Override
40+
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
41+
super.onActivityCreated(savedInstanceState);
42+
_setupLogAdapter();
43+
}
44+
45+
@OnClick(R.id.accumulated_event_btn)
46+
public void onButtonTapped() {
47+
48+
_addLogToAdapter("Tapped");
49+
}
50+
51+
// -----------------------------------------------------------------------------------
52+
// Method that help wiring up the example (irrelevant to RxJava)
53+
54+
private void _setupLogAdapter() {
55+
_logs = new ArrayList<String>();
56+
_adapter = new LogAdapter(getActivity(), new ArrayList<String>());
57+
_logsListView.setAdapter(_adapter);
58+
}
59+
60+
private void _addLogToAdapter(String logMsg) {
61+
_logs.add(0, logMsg);
62+
_adapter.clear();
63+
_adapter.addAll(_logs);
64+
}
65+
66+
private class LogAdapter
67+
extends ArrayAdapter<String> {
68+
69+
public LogAdapter(Context context, List<String> logs) {
70+
super(context, R.layout.item_log, R.id.item_log, logs);
71+
}
72+
}
2573
}
Collapse file

‎app/src/main/res/layout/fragment_accumulate.xml‎

Copy file name to clipboardExpand all lines: app/src/main/res/layout/fragment_accumulate.xml
+18-2Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,24 @@
77
xmlns:android="http://schemas.android.com/apk/res/android">
88

99
<TextView
10-
android:layout_width="wrap_content"
1110
android:layout_height="wrap_content"
12-
android:text="Accumulate events test" />
11+
android:layout_width="match_parent"
12+
android:padding="10dp"
13+
android:gravity="center"
14+
android:text="@string/demo_accumulate_msg"/>
15+
16+
<Button
17+
android:id="@+id/accumulated_event_btn"
18+
android:layout_height="wrap_content"
19+
android:layout_width="match_parent"
20+
android:layout_marginLeft="90dp"
21+
android:layout_marginRight="90dp"
22+
android:textSize="16dp"
23+
android:text="tap me"/>
24+
25+
<ListView
26+
android:id="@+id/accumulated_event_list"
27+
android:layout_height="match_parent"
28+
android:layout_width="match_parent"/>
1329

1430
</LinearLayout>
Collapse file

‎app/src/main/res/layout/item_log.xml‎

Copy file name to clipboard
+8Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
3+
<TextView
4+
android:id="@+id/item_log"
5+
android:layout_height="match_parent"
6+
android:layout_width="match_parent"
7+
android:text="Item Log goes here"
8+
xmlns:android="http://schemas.android.com/apk/res/android"/>
Collapse file

‎app/src/main/res/values/strings.xml‎

Copy file name to clipboardExpand all lines: app/src/main/res/values/strings.xml
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,6 @@
66
<string name="action_settings">Settings</string>
77
<string name="demo_type_long_bg">long operation in bg (schedulers)</string>
88
<string name="demo_type_accumulate">accumulate events (instant search)</string>
9+
<string name="demo_accumulate_msg">This is a demonstration of how events are accumulated. Tap the button below repetitively and you will notice in the logs that button taps are collected over a span of 2s and printed below.</string>
910

1011
</resources>

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.