我无法弄清楚为什么echo $difference->format('%d')
中没有显示任何内容。我所做的只是按一个按钮,我想要导航到RecyclerView
我将看到我的粉丝列表。以下是我的代码:
XML布局:
follow_list.xml:
Activity
follow_item.xml:
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
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:id="@+id/follow_list_layout_id"
android:layout_height="match_parent" android:fitsSystemWindows="true">
<android.support.design.widget.AppBarLayout
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:theme="@style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
android:id="@+id/follow_toolbar"
app:popupTheme="@style/AppTheme.PopupOverlay"
app:theme="@style/AppTheme.AppBarOverlay"/>
</android.support.design.widget.AppBarLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<!--<include layout="@layout/include_progress_overlay"/>-->
<android.support.v7.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/follow_list"
/>
</RelativeLayout>
</android.support.design.widget.CoordinatorLayout>
适配器:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:facebook="http://schemas.android.com/apk/res-auto"
xmlns:fresco="http://schemas.android.com/tools"
android:layout_height="wrap_content"
android:layout_width="match_parent">
<android.support.v7.widget.CardView
android:layout_height="58dp"
android:layout_width="match_parent"
android:id="@+id/follower_card_view">
<RelativeLayout
android:background="@drawable/edittext_bg"
android:orientation="horizontal"
android:layout_width="match_parent"
android:paddingTop="8dp"
android:layout_height="match_parent"
android:paddingBottom="8dp">
<com.facebook.drawee.view.SimpleDraweeView
android:id="@+id/follower_profile_picture"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
fresco:placeholderImageScaleType="centerCrop"
fresco:placeholderImage="@mipmap/blank_prof_pic"
fresco:roundedCornerRadius="5dp"
fresco:roundAsCircle="true"
/>
<TextView
android:layout_marginLeft="72dp"
android:id="@+id/follower_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="16sp"
android:fontFamily="sans-serif-medium"
android:layout_centerVertical="true" />
<CheckBox
android:id="@+id/follower_checkbox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:focusable="false"
android:paddingRight="16dp"
android:focusableInTouchMode="false"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_alignParentEnd="true" />
</RelativeLayout>
</android.support.v7.widget.CardView>
</LinearLayout>
显示关注者的类:
public class FollowerRecyclerViewAdapter extends RecyclerView.Adapter<FollowerRecyclerViewAdapter.FollowerViewHolder>{
private List<User> followers;
public void setFollowers(List<User> followers) {
this.followers = followers;
}
public static User containsId(List<User> list, String id) {
for (User object : list) {
if (object.getUserId().equals(id)) {
return object;
}
}
return null;
}
public FollowerRecyclerViewAdapter(List<User> followers) {
this.followers = followers;
}
public List<User> getFollowers(){
return this.followers;
}
@Override
public int getItemCount() {
return followers.size();
}
public static class FollowerViewHolder extends RecyclerView.ViewHolder {
CardView cardViewfollower;
TextView name;
CheckBox isFollowingCheckBox;
SimpleDraweeView followerProfilePhoto;
FollowerViewHolder(View itemView) {
super(itemView);
cardViewfollower = (CardView) itemView.findViewById(R.id.follower_card_view);
name = (TextView) itemView.findViewById(R.id.follower_name);
followerProfilePhoto = (SimpleDraweeView) itemView.findViewById(R.id.follower_profile_picture);
isFollowingCheckBox = (CheckBox) itemView.findViewById(R.id.follower_checkbox);
}
}
@Override
public void onBindViewHolder(FollowerViewHolder followerViewHolder, int i) {
final User currentItem = getItem(i);
followerViewHolder.name.setText(currentItem.getName());
DraweeController controller = TabsUtil.getImage(currentItem.getUserId());
RoundingParams roundingParams = RoundingParams.fromCornersRadius(5f);
roundingParams.setRoundAsCircle(true);
followerViewHolder.followerProfilePhoto.getHierarchy().setRoundingParams(roundingParams);
followerViewHolder.followerProfilePhoto.setController(controller);
}
@Override
public FollowerViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) {
View v = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.follower_item, viewGroup, false);
FollowerViewHolder pvh = new FollowerViewHolder(v);
return pvh;
}
private User getItem(int position)
{
return followers.get(position);
}
public void add(User follower){
for(int i = 0; i < followers.size(); i++) {
if(follower.getId().equals(followers.get(i).getId())) {
return;
}
}
followers.add(follower);
notifyItemInserted(followers.size() + 1);
notifyItemRangeChanged(followers.size() + 1, followers.size());
}
public void remove(Follower item) {
int position = followers.indexOf(item);
followers.remove(position);
notifyItemRemoved(position);
}
@Override
public void onAttachedToRecyclerView(RecyclerView recyclerView) {
super.onAttachedToRecyclerView(recyclerView);
}
我不确定为什么public class FollowingList extends AppCompatActivity {
FireBaseApplication application;
DatabaseQuery databaseQuery;
View progressOverlay;
String posterUserId;
String posterName;
String postStatus;
String postTimeStamp;
String postTitle;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.follow_list);
application = ((FireBaseApplication) getApplication());
databaseQuery = new DatabaseQuery(this);
//Set up action bar
setupActionBar();
progressOverlay = findViewById(R.id.progress_overlay);
//AndroidUtils.animateView(progressOverlay, View.VISIBLE, 0.9f, 200);
setupActivity(savedInstanceState);
//All we need to do is render the page now
RecyclerView recyclerView = (RecyclerView) findViewById(R.id.follow_list);
RecyclerView.ItemAnimator animator = recyclerView.getItemAnimator();
if (animator instanceof SimpleItemAnimator) {
((SimpleItemAnimator) animator).setSupportsChangeAnimations(false);
}
//Assuming we refresh the followers list, we have to make sure that new followers are loaded
application.getFollowingRecyclerViewAdapter().notifyDataSetChanged();
LinearLayoutManager llm = new LinearLayoutManager(this);
recyclerView.setLayoutManager(llm);
recyclerView.setAdapter(application.getFollowingRecyclerViewAdapter());
}
private void setupActionBar(){
Toolbar toolbar = (Toolbar) findViewById(R.id.follow_toolbar);
setSupportActionBar(toolbar);
//Back bar enabled
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setDisplayShowHomeEnabled(true);
getSupportActionBar().setDisplayShowCustomEnabled(true);
//Toggle bar enabled
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
onBackPressed();
return true;
default:
return super.onOptionsItemSelected(item);
}
}
}
没有显示我RecyclerView
的任何内容,但我们将不胜感激。谢谢!