2017-05-08 51 views
0

我試圖在我的Recyclerview中顯示我的整數保存在Firebase數據庫中。我有兩個字符串可以在我的應用程序中輕鬆顯示,但不知何故,它不適用於整數。更奇怪的是,當我保存一個字符串之前有一個整數我得到一個錯誤。在Android應用程序中的文本框內的Firebase顯示整數

這裏我的數據庫結構

enter image description here

在這裏,我填充我Viewholder

@Override 
public void onStart() { 
    super.onStart(); 
     firebaseRecyclerAdapter = new FirebaseRecyclerAdapter<ListItem, ListViewHolder>(

       ListItem.class, 
       R.layout.card_item, 
       ListViewHolder.class, 

       mDatabase.orderByChild("minusAccandShare").endAt(0) 
     ) { 


      @Override 
      protected void populateViewHolder(ListViewHolder viewHolder, ListItem model, final int position) { 

       viewHolder.setImage(getActivity().getApplicationContext(), model.getImage()); 
       viewHolder.setHeading(model.getHeading()); 
       viewHolder.setStoreName(model.getStoreName()); 
       viewHolder.setAcceptCount(model.getAcceptCount()); 

       viewHolder.mView.setOnClickListener(new View.OnClickListener(){ 

        @Override 
        public void onClick(View view) { 
         Intent i = new Intent(getActivity(), DetailActivity.class); 
         Bundle extras = new Bundle(); 
         extras.putString(EXTRA_QUOTE, firebaseRecyclerAdapter.getRef(position).getKey()); 
         i.putExtra(BUNDLE_EXTRAS, extras); 
         startActivity(i); 
        } 
       }); 
      } 

     }; 
    recyclerView.setAdapter(firebaseRecyclerAdapter); 
} 

我ViewHolder

public static class ListViewHolder extends RecyclerView.ViewHolder { 

    View mView; 

    public ListViewHolder(View itemView) { 
     super(itemView); 

     mView = itemView; 
    } 

    public void setImage(Context ctx, String image){ 
     ImageView postImage = (ImageView) mView.findViewById(R.id.im_item_icon); 
     Picasso.with(ctx).load(image).resize(200,200).into(postImage); 
    } 

    public void setHeading(String heading){ 
     TextView card_heading = (TextView) mView.findViewById(R.id.lbl_item_sub_title); 
     card_heading.setText(heading); 
    } 

    public void setStoreName(String storeName){ 
     TextView card_storeName = (TextView) mView.findViewById(R.id.lbl_item_text); 
     card_storeName.setText(storeName); 
    } 

    public void setAcceptCount(String accepts){ 
     TextView accepts_count = (TextView) mView.findViewById(R.id.lbl_accepts_count); 
     accepts_count.setText(accepts); 
    } 
} 

最後我的模型

public class ListItem { 

private String heading, storeName, image; 
private Long accepts; 

public ListItem() { 

} 

public ListItem(String heading,String storeName, Long accepts, String image){ 
    this.heading = heading; 
    this.storeName = storeName; 
    this.image = image; 
    this.accepts = accepts; 
} 

public String getHeading() { 
    return heading; 
} 
public String getStoreName() { 
    return storeName; 
} 
public String getImage() {return image;} 
public String getAcceptCount() { 
    return String.valueOf(accepts); 
} 

以這種方式,我看到null應該站在200代替。我嘗試了一切。我甚至保存了一個字符串,而不是一個整數,並嘗試以與標題字符串相同的方式顯示它(完美地工作),但後來我看到一個空白的地方...請幫助。謝謝

回答

1

你應該爲ListItem中的接受創建一個getter和setter。

public Long getAccepts() { 
    return accepts; 
} 

public void setAccepts(Long accepts) { 
    this.accepts = accepts; 
} 
+0

我知道我把它聲明爲Long。但無論如何它都不起作用。我不能看到錯誤 –

+0

謝謝你的工作.... –

+0

然後請接受答案。 –

相關問題