Firebase数据在我的RecyclerView中不会加载

huangapple go评论105阅读模式
英文:

Firebase data won't load in my RecyclerView

问题

  1. The screen launches but doesn't throw any errors or bugs. I just launch the blank recycler view as if it's not reading any of the Java codes, although they are in my manifest. I've tried bumping the Firebase path down to "Book," but then I receive a `can't convert object to java.lang.string` error.
  2. **Main activity**
  3. public class BarberView extends AppCompatActivity {
  4. private ArrayList<Book> books;
  5. private List<String> key;
  6. private Context mContext;
  7. private static final String TAG = "RealtimeDatabaseDemo";
  8. private MyViewHolder adapter;
  9. private TextView list_u, list_p, list_d, list_t, list_c;
  10. DatabaseReference ref;
  11. private FirebaseRecyclerOptions<Book> options;
  12. RecyclerView recyclerView;
  13. @Override
  14. protected void onCreate(@Nullable Bundle savedInstanceState) {
  15. super.onCreate(savedInstanceState);
  16. setContentView(R.layout.barber_view);
  17. recyclerView = findViewById(R.id.list_jobs);
  18. recyclerView.setHasFixedSize(false);
  19. recyclerView.setLayoutManager(new LinearLayoutManager(this));
  20. ref = FirebaseDatabase.getInstance().getReference();
  21. Query query = ref.child("gregs-281717");
  22. final FirebaseRecyclerOptions<Book> options = new FirebaseRecyclerOptions.Builder<Book>()
  23. .setQuery(query, Book.class)
  24. .setLifecycleOwner(this)
  25. .build();
  26. adapter = new MyViewHolder(options);
  27. recyclerView.setAdapter(adapter);
  28. query.addValueEventListener(new ValueEventListener() {
  29. @Override
  30. public void onDataChange(@NonNull DataSnapshot snapshot) {
  31. for (DataSnapshot mdatasnapshot : snapshot.getChildren()) {
  32. Book mbook = new Book();
  33. mbook.setTime(mdatasnapshot.getValue().toString());
  34. mbook.setDates(mdatasnapshot.getValue().toString());
  35. mbook.setPayDone(mdatasnapshot.getValue().toString());
  36. mbook.setCutDone(mdatasnapshot.getValue().toString());
  37. mbook.setUser_id(mdatasnapshot.getValue().toString());
  38. books.add(mbook);
  39. }
  40. adapter = new MyViewHolder(options);
  41. adapter.notifyDataSetChanged();
  42. }
  43. @Override
  44. public void onCancelled(@NonNull DatabaseError error) {
  45. }
  46. });
  47. }
  48. @Override
  49. public void onStart() {
  50. super.onStart();
  51. adapter.startListening();
  52. adapter.notifyDataSetChanged();
  53. }
  54. @Override
  55. protected void onStop() {
  56. super.onStop();
  57. adapter.startListening();
  58. adapter.notifyDataSetChanged();
  59. }
  60. }
  61. **ViewHolder**
  62. public class MyViewHolder extends FirebaseRecyclerAdapter<Book, MyViewHolder.Holder> {
  63. public MyViewHolder(@NonNull FirebaseRecyclerOptions<Book> options) {
  64. super(options);
  65. }
  66. @Override
  67. protected void onBindViewHolder(@NonNull Holder holder, int position, @NonNull Book book) {
  68. holder.list_u.setText(book.getUser_id());
  69. holder.list_c.setText(book.getCutDone());
  70. holder.list_d.setText(book.getDates());
  71. holder.list_t.setText(book.getTime());
  72. holder.list_p.setText(book.getPayDone());
  73. }
  74. @NonNull
  75. @Override
  76. public Holder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
  77. View view = LayoutInflater.from(parent.getContext())
  78. .inflate(R.layout.list_item, parent, false);
  79. return new Holder(view);
  80. }
  81. class Holder extends RecyclerView.ViewHolder {
  82. public TextView list_u, list_p, list_d, list_t, list_c;
  83. public Holder(@NonNull View itemView) {
  84. super(itemView);
  85. list_u = itemView.findViewById(R.id.list_user);
  86. list_p = itemView.findViewById(R.id.list_price);
  87. list_d = itemView.findViewById(R.id.list_date);
  88. list_t = itemView.findViewById(R.id.list_time);
  89. list_c = itemView.findViewById(R.id.list_cut);
  90. }
  91. }
  92. }
  93. **Model**
  94. import com.google.firebase.database.IgnoreExtraProperties;
  95. import org.jetbrains.annotations.NotNull;
  96. @IgnoreExtraProperties
  97. public class Book {
  98. public String time;
  99. public String dates;
  100. public String payDone;
  101. public String cutDone;
  102. public String user_id;
  103. public Book() {
  104. }
  105. @NotNull
  106. @Override
  107. public String toString() {
  108. return "Book{" +
  109. "time='" + time + '\'' +
  110. ", dates='" + dates + '\'' +
  111. ", payDone='" + payDone + '\'' +
  112. ", cutDone='" + cutDone + '\'' +
  113. ", user_id='" + user_id + '\'' +
  114. '}';
  115. }
  116. public Book(String time, String dates, String cutDone, String payDone, String user_id) {
  117. this.time = time;
  118. this.dates = dates;
  119. this.payDone = payDone;
  120. this.cutDone = cutDone;
  121. this.user_id = user_id;
  122. }
  123. public String getTime() {
  124. return time;
  125. }
  126. public void setTime(String time) {
  127. this.time = time;
  128. }
  129. public String getDates() {
  130. return dates;
  131. }
  132. public void setDates(String dates) {
  133. this.dates = dates;
  134. }
  135. public String getPayDone() {
  136. return payDone;
  137. }
  138. public void setPayDone(String payDone) {
  139. this.payDone = payDone;
  140. }
  141. public String getCutDone() {
  142. return cutDone;
  143. }
  144. public void setCutDone(String cutDone) {
  145. this.cutDone = cutDone;
  146. }
  147. public String getUser_id() {
  148. return user_id;
  149. }
  150. public void setUser_id(String user_id) {
  151. this.user_id = user_id;
  152. }
  153. }
  154. **RecyelerView.xml**
  155. <?xml version="1.0" encoding="utf-8"?>
  156. <androidx.constraintlayout.widget.ConstraintLayout
  157. xmlns:android="http://schemas.android.com/apk/res/android"
  158. xmlns:app="http://schemas.android.com/apk/res-auto"
  159. xmlns:tools="http://schemas.android.com/tools"
  160. android:layout_width="match_parent"
  161. android:layout_height="match_parent"
  162. tools:context=".BarberView">
  163. <androidx.recyclerview.widget.RecyclerView
  164. android:layout_width="match_parent"
  165. android:layout_height="match_parent"
  166. android:id="@+id/list_jobs"/>
  167. </androidx.constraintlayout.widget.ConstraintLayout>
  168. **List.XML**
  169. <?xml version="1.0" encoding="utf-8"?>
  170. <androidx.constraintlayout.widget.ConstraintLayout
  171. xmlns:android="http://schemas.android.com/apk/res/android"
  172. xmlns:app="http://schemas.android.com/apk/res-auto"
  173. xmlns:tools="http://schemas.android.com/tools"
  174. android:layout_width="match_parent"
  175. android:layout_height="wrap_content"
  176. android:padding="16dp"
  177. android:id="@+id/list_books">
  178. <TextView
  179. android:textColor="#000000"
  180. android:id="@+id/list_cut"
  181. android:layout_width="wrap_content"
  182. android:layout_height="wrap_content"
  183. android:text="TextView"
  184. app:layout_constraintBottom_toBottomOf="parent"
  185. app:layout_constraintStart_toStartOf="parent"
  186. app:layout_constraintTop_toTopOf="parent" />
  187. <TextView
  188. android:id="@+id/list_price"
  189. android:layout_width="62dp"
  190. android:layout_height="19dp"
  191. android:text="TextView"
  192. android:textSize="14sp"
  193. android:textColor="#000000"
  194. app:layout_constraintBottom_toBottomOf="parent"
  195. app:layout_constraintEnd_toStartOf="@+id/list_date"
  196. app:layout_constraintStart_toEndOf="@+id/list_cut"
  197. app:layout_constraintTop_toTopOf="parent
  198. <details>
  199. <summary>英文:</summary>
  200. The screen launches but doesn&#39;t throw any errors or bugs I just launch the blank recycler view as if it&#39;s not reading any of the java codes although they are in my manifest. I&#39;ve tried bumping the firebase path down on to &quot;Book&quot; but then I receive a `can&#39;t convert object to java.lang.string` error.
  201. **Main activity**
  202. public class BarberView extends AppCompatActivity {
  203. private ArrayList&lt;Book&gt; books ;
  204. private List&lt;String&gt; key;
  205. private Context mContext;
  206. private static final String TAG = &quot;RealtimeDatabaseDemo&quot;;
  207. private MyViewHolder adapter;
  208. private TextView list_u, list_p, list_d, list_t, list_c;
  209. DatabaseReference ref;
  210. private FirebaseRecyclerOptions&lt;Book&gt; options;
  211. /**
  212. * Get the last 50 chat messages.
  213. */
  214. RecyclerView recyclerView;
  215. @Override
  216. protected void onCreate(@Nullable Bundle savedInstanceState) {
  217. super.onCreate ( savedInstanceState );
  218. setContentView ( R.layout.barber_view );
  219. recyclerView =findViewById ( R.id.list_jobs );
  220. recyclerView.setHasFixedSize ( false );
  221. recyclerView.setLayoutManager ( new LinearLayoutManager ( this ) );
  222. ref = FirebaseDatabase.getInstance ( ).getReference ( );
  223. Query query = ref.child ( &quot;gregs-281717&quot; );
  224. final FirebaseRecyclerOptions&lt;Book&gt; options=new FirebaseRecyclerOptions.Builder&lt;Book&gt; ( )
  225. .setQuery ( query, Book.class )
  226. .setLifecycleOwner ( this )
  227. .build ( );
  228. adapter = new MyViewHolder ( options );
  229. recyclerView.setAdapter ( adapter );
  230. query.addValueEventListener ( new ValueEventListener ( ) {
  231. @Override
  232. public void onDataChange(@NonNull DataSnapshot snapshot) {
  233. for (DataSnapshot mdatasnapshot: snapshot.getChildren()) {
  234. Book mbook =new Book();
  235. mbook.setTime( mdatasnapshot.getValue ( ).toString () );
  236. mbook.setDates( mdatasnapshot.getValue ( ).toString () );
  237. mbook.setPayDone( mdatasnapshot.getValue ( ).toString () );
  238. mbook.setCutDone( mdatasnapshot.getValue ( ).toString () );
  239. mbook.setUser_id( mdatasnapshot.getValue ( ).toString () );
  240. books.add(mbook);
  241. }
  242. adapter = new MyViewHolder (options );
  243. adapter.notifyDataSetChanged();
  244. }
  245. @Override
  246. public void onCancelled(@NonNull DatabaseError error) {
  247. }
  248. });
  249. }
  250. @Override
  251. public void onStart() {
  252. super.onStart ( );
  253. adapter.startListening ();
  254. adapter.notifyDataSetChanged();
  255. }
  256. @Override
  257. protected void onStop() {
  258. super.onStop ( );
  259. adapter.startListening ();
  260. adapter.notifyDataSetChanged();
  261. }
  262. }
  263. **ViewHolder**
  264. public class MyViewHolder extends FirebaseRecyclerAdapter&lt;Book, MyViewHolder.Holder&gt; {
  265. /**
  266. * Initialize a {@link RecyclerView.Adapter} that listens to a Firebase query. See
  267. * {@link FirebaseRecyclerOptions} for configuration options.
  268. *
  269. * @param options
  270. */
  271. public MyViewHolder(@NonNull FirebaseRecyclerOptions&lt;Book&gt; options) {
  272. super ( options );
  273. }
  274. @Override
  275. protected void onBindViewHolder(@NonNull Holder holder, int position, @NonNull Book book) {
  276. holder.list_u.setText ( book.getUser_id () );
  277. holder.list_c.setText ( book.getCutDone () );
  278. holder.list_d.setText ( book.getDates () );
  279. holder.list_t.setText ( book.getTime () );
  280. holder.list_p.setText ( book.getPayDone () );
  281. }
  282. @NonNull
  283. @Override
  284. public Holder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
  285. View view = LayoutInflater.from ( parent.getContext ( ) )
  286. .inflate ( R.layout.list_item, parent, false );
  287. return new Holder ( view );
  288. }
  289. class Holder extends RecyclerView.ViewHolder{
  290. public TextView list_u, list_p, list_d, list_t, list_c;
  291. public Holder(@NonNull View itemView) {
  292. super(itemView);
  293. list_u = itemView.findViewById ( R.id.list_user );
  294. list_p = itemView.findViewById ( R.id.list_price );
  295. list_d = itemView.findViewById ( R.id.list_date );
  296. list_t = itemView.findViewById ( R.id.list_time );
  297. list_c = itemView.findViewById ( R.id.list_cut );
  298. }}
  299. }
  300. **Model**
  301. import com.google.firebase.database.IgnoreExtraProperties;
  302. import org.jetbrains.annotations.NotNull;
  303. @IgnoreExtraProperties
  304. public class Book {
  305. public String time;
  306. public String dates;
  307. public String payDone;
  308. public String cutDone;
  309. public String user_id;
  310. public Book() {
  311. }
  312. @NotNull
  313. @Override
  314. public String toString() {
  315. return &quot;Book{&quot; +
  316. &quot;time=&#39;&quot; + time + &#39;\&#39;&#39; +
  317. &quot;, dates=&#39;&quot; + dates + &#39;\&#39;&#39; +
  318. &quot;, payDone=&#39;&quot; + payDone + &#39;\&#39;&#39; +
  319. &quot;, cutDone=&#39;&quot; + cutDone + &#39;\&#39;&#39; +
  320. &quot;, user_id=&#39;&quot; + user_id + &#39;\&#39;&#39; +
  321. &#39;}&#39;;
  322. }
  323. public Book(String time, String dates, String cutDone, String payDone, String user_id) {
  324. this.time = time;
  325. this.dates = dates;
  326. this.payDone = payDone;
  327. this.cutDone = cutDone;
  328. this.user_id = user_id;
  329. }
  330. public String getTime() {
  331. return time;
  332. }
  333. public void setTime(String time) {
  334. this.time = time;
  335. }
  336. public String getDates() {
  337. return dates;
  338. }
  339. public void setDates(String dates) {
  340. this.dates = dates;
  341. }
  342. public String getPayDone() {
  343. return payDone;
  344. }
  345. public void setPayDone(String payDone) {
  346. this.payDone = payDone;
  347. }
  348. public String getCutDone() {
  349. return cutDone;
  350. }
  351. public void setCutDone(String cutDone) {
  352. this.cutDone = cutDone;
  353. }
  354. public String getUser_id() {
  355. return user_id;
  356. }
  357. public void setUser_id(String user_id) {
  358. this.user_id = user_id;
  359. }
  360. }
  361. **RecyelerView.xml**
  362. &lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
  363. &lt;androidx.constraintlayout.widget.ConstraintLayout
  364. xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;
  365. xmlns:app=&quot;http://schemas.android.com/apk/res-auto&quot;
  366. xmlns:tools=&quot;http://schemas.android.com/tools&quot;
  367. android:layout_width=&quot;match_parent&quot;
  368. android:layout_height=&quot;match_parent&quot;
  369. tools:context=&quot;.BarberView&quot;&gt;
  370. &lt;androidx.recyclerview.widget.RecyclerView
  371. android:layout_width=&quot;match_parent&quot;
  372. android:layout_height=&quot;match_parent&quot;
  373. android:id=&quot;@+id/list_jobs&quot;/&gt;
  374. &lt;/androidx.constraintlayout.widget.ConstraintLayout&gt;
  375. **List.XML**
  376. &lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
  377. &lt;androidx.constraintlayout.widget.ConstraintLayout
  378. xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;
  379. xmlns:app=&quot;http://schemas.android.com/apk/res-auto&quot;
  380. xmlns:tools=&quot;http://schemas.android.com/tools&quot;
  381. android:layout_width=&quot;match_parent&quot;
  382. android:layout_height=&quot;wrap_content&quot;
  383. android:padding=&quot;16dp&quot;
  384. android:id=&quot;@+id/list_books&quot;&gt;
  385. &lt;TextView
  386. android:textColor=&quot;#000000&quot;
  387. android:id=&quot;@+id/list_cut&quot;
  388. android:layout_width=&quot;wrap_content&quot;
  389. android:layout_height=&quot;wrap_content&quot;
  390. android:text=&quot;TextView&quot;
  391. app:layout_constraintBottom_toBottomOf=&quot;parent&quot;
  392. app:layout_constraintStart_toStartOf=&quot;parent&quot;
  393. app:layout_constraintTop_toTopOf=&quot;parent&quot; /&gt;
  394. &lt;TextView
  395. android:id=&quot;@+id/list_price&quot;
  396. android:layout_width=&quot;62dp&quot;
  397. android:layout_height=&quot;19dp&quot;
  398. android:text=&quot;TextView&quot;
  399. android:textSize=&quot;14sp&quot;
  400. android:textColor=&quot;#000000&quot;
  401. app:layout_constraintBottom_toBottomOf=&quot;parent&quot;
  402. app:layout_constraintEnd_toStartOf=&quot;@+id/list_date&quot;
  403. app:layout_constraintStart_toEndOf=&quot;@+id/list_cut&quot;
  404. app:layout_constraintTop_toTopOf=&quot;parent&quot; /&gt;
  405. &lt;TextView
  406. android:id=&quot;@+id/list_time&quot;
  407. android:layout_width=&quot;wrap_content&quot;
  408. android:layout_height=&quot;wrap_content&quot;
  409. android:text=&quot;TextView&quot;
  410. android:textColor=&quot;#000000&quot;
  411. app:layout_constraintBottom_toBottomOf=&quot;parent&quot;
  412. app:layout_constraintEnd_toEndOf=&quot;parent&quot;
  413. app:layout_constraintTop_toTopOf=&quot;parent&quot;
  414. tools:ignore=&quot;MissingConstraints&quot; /&gt;
  415. &lt;TextView
  416. android:id=&quot;@+id/list_date&quot;
  417. android:layout_width=&quot;wrap_content&quot;
  418. android:layout_height=&quot;wrap_content&quot;
  419. android:text=&quot;TextView&quot;
  420. android:textColor=&quot;#000000&quot;
  421. app:layout_constraintBottom_toBottomOf=&quot;parent&quot;
  422. app:layout_constraintEnd_toEndOf=&quot;parent&quot;
  423. app:layout_constraintStart_toStartOf=&quot;parent&quot;
  424. app:layout_constraintTop_toTopOf=&quot;parent&quot; /&gt;
  425. &lt;TextView
  426. android:id=&quot;@+id/list_user&quot;
  427. android:layout_width=&quot;wrap_content&quot;
  428. android:layout_height=&quot;wrap_content&quot;
  429. android:text=&quot;TextView&quot;
  430. android:textColor=&quot;#000000&quot;
  431. app:layout_constraintBottom_toBottomOf=&quot;parent&quot;
  432. app:layout_constraintEnd_toStartOf=&quot;@+id/list_time&quot;
  433. app:layout_constraintStart_toEndOf=&quot;@+id/list_date&quot;
  434. app:layout_constraintTop_toTopOf=&quot;parent&quot; /&gt;
  435. **gregs-281717.jason Firebase realtime database**
  436. {
  437. &quot;Book&quot; : {
  438. &quot;cutDone&quot; : &quot;cut1&quot;,
  439. &quot;dates&quot; : &quot;11/9/2020&quot;,
  440. &quot;payDone&quot; : &quot;20.00&quot;,
  441. &quot;time&quot; : &quot;03:36AM&quot;,
  442. &quot;user_id&quot; : &quot;notme@badcode.com&quot;
  443. }
  444. }
  445. </details>
  446. # 答案1
  447. **得分**: 0
  448. 你应该在从Firebase加载数据后,在你的主活动中设置适配器,就像这样:
  449. ```java
  450. public class BarberView extends AppCompatActivity {
  451. private ArrayList<Book> books;
  452. private List<String> key;
  453. private Context mContext;
  454. private static final String TAG = "RealtimeDatabaseDemo";
  455. private MyViewHolder adapter;
  456. private TextView list_u, list_p, list_d, list_t, list_c;
  457. DatabaseReference ref;
  458. private FirebaseRecyclerOptions<Book> options;
  459. RecyclerView recyclerView;
  460. @Override
  461. protected void onCreate(@Nullable Bundle savedInstanceState) {
  462. super.onCreate(savedInstanceState);
  463. setContentView(R.layout.barber_view);
  464. recyclerView = findViewById(R.id.list_jobs);
  465. recyclerView.setHasFixedSize(false);
  466. recyclerView.setLayoutManager(new LinearLayoutManager(this));
  467. ref = FirebaseDatabase.getInstance().getReference();
  468. Query query = ref.child("gregs-281717");
  469. final FirebaseRecyclerOptions<Book> options = new FirebaseRecyclerOptions.Builder<Book>()
  470. .setQuery(query, Book.class)
  471. .setLifecycleOwner(this)
  472. .build();
  473. query.addValueEventListener(new ValueEventListener() {
  474. @Override
  475. public void onDataChange(@NonNull DataSnapshot snapshot) {
  476. for (DataSnapshot mdatasnapshot : snapshot.getChildren()) {
  477. Book mbook = new Book();
  478. mbook.setTime(mdatasnapshot.child("Book").getValue(true).toString());
  479. mbook.setDates(mdatasnapshot.getValue(true).toString());
  480. mbook.setPayDone(mdatasnapshot.getValue(true).toString());
  481. mbook.setCutDone(mdatasnapshot.getValue(true).toString());
  482. mbook.setUser_id(mdatasnapshot.getValue(true).toString());
  483. }
  484. adapter = new MyViewHolder(options);
  485. recyclerView.setAdapter(adapter);
  486. adapter.notifyDataSetChanged();
  487. }
  488. @Override
  489. public void onCancelled(@NonNull DatabaseError error) {
  490. }
  491. });
  492. }
  493. @Override
  494. public void onStart() {
  495. super.onStart();
  496. recyclerView.setAdapter(adapter);
  497. }
  498. @Override
  499. protected void onStop() {
  500. super.onStop();
  501. recyclerView.setAdapter(adapter);
  502. }
  503. }
英文:

You should set your adapter after loading data from firebase in your main activity

like this :-

  1. public class BarberView extends AppCompatActivity {
  2. private ArrayList&lt;Book&gt; books ;
  3. private List&lt;String&gt; key;
  4. private Context mContext;
  5. private static final String TAG = &quot;RealtimeDatabaseDemo&quot;;
  6. private MyViewHolder adapter;
  7. private TextView list_u, list_p, list_d, list_t, list_c;
  8. DatabaseReference ref;
  9. private FirebaseRecyclerOptions&lt;Book&gt; options;
  10. /**
  11. * Get the last 50 chat messages.
  12. */
  13. RecyclerView recyclerView;
  14. @Override
  15. protected void onCreate(@Nullable Bundle savedInstanceState) {
  16. super.onCreate ( savedInstanceState );
  17. setContentView ( R.layout.barber_view );
  18. recyclerView =findViewById ( R.id.list_jobs );
  19. recyclerView.setHasFixedSize ( false );
  20. recyclerView.setLayoutManager ( new LinearLayoutManager ( this ) );
  21. ref = FirebaseDatabase.getInstance ( ).getReference ( );
  22. Query query = ref.child ( &quot;gregs-281717&quot; );
  23. final FirebaseRecyclerOptions&lt;Book&gt; options=new FirebaseRecyclerOptions.Builder&lt;Book&gt; ( )
  24. .setQuery ( query, Book.class )
  25. .setLifecycleOwner ( this )
  26. .build ( );
  27. query.addValueEventListener ( new ValueEventListener ( ) {
  28. @Override
  29. public void onDataChange(@NonNull DataSnapshot snapshot) {
  30. for (DataSnapshot mdatasnapshot: snapshot.getChildren()) {
  31. Book mbook =new Book();
  32. mbook.setTime( mdatasnapshot.child ( &quot;Book&quot; ).getValue ( true).toString () );
  33. mbook.setDates( mdatasnapshot.getValue (true ).toString () );
  34. mbook.setPayDone( mdatasnapshot.getValue ( true).toString () );
  35. mbook.setCutDone( mdatasnapshot.getValue (true ).toString () );
  36. mbook.setUser_id( mdatasnapshot.getValue ( true).toString () );
  37. }
  38. adapter = new MyViewHolder (options );
  39. recyclerView.setAdapter(adapter);
  40. adapter.notifyDataSetChanged();
  41. }
  42. @Override
  43. public void onCancelled(@NonNull DatabaseError error) {
  44. }
  45. });
  46. }
  47. @Override
  48. public void onStart() {
  49. super.onStart ( );
  50. recyclerView.setAdapter(adapter);
  51. }
  52. @Override
  53. protected void onStop() {
  54. super.onStop ( );
  55. recyclerView.setAdapter(adapter);
  56. }
  57. }

huangapple
  • 本文由 发表于 2020年9月12日 01:42:20
  • 转载请务必保留本文链接:https://go.coder-hub.com/63851911.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定