如何显示创建Recyclerview中的项目的时间?

时间:2018-05-28 23:02:47

标签: java android android-layout android-recyclerview recycler-adapter

我想这样做:

Mockup Image

我有RecyclerView,其中对于我创建的每个项目,我想显示项目创建的时间。我想在这个项目中显示时间。

我的代码:

public class VerIncidencia extends AppCompatActivity {

private FirebaseRecyclerAdapter mAdapter;
private DatabaseReference mDatabase;
String idIncidencia;
String idEmpresa;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_ver_incidencia);

    String uid = FirebaseAuth.getInstance().getUid();
    idIncidencia = getIntent().getStringExtra("INCIDENCIA_KEY");

    idEmpresa = getIntent().getStringExtra("EMPRESA_KEY");


    mDatabase = FirebaseDatabase.getInstance().getReference().child("incidencia").child(uid);

    RecyclerView recyclerView = findViewById(R.id.list_view);
    recyclerView.setLayoutManager(new LinearLayoutManager(this));

    Query postsQuery = mDatabase;

    FirebaseRecyclerOptions options = new FirebaseRecyclerOptions.Builder<Incidencia>()
            .setQuery(postsQuery, Incidencia.class)
            .setLifecycleOwner(this)
            .build();
    mAdapter = new FirebaseRecyclerAdapter<Incidencia, IncidenciaViewHolder>(options) {
        @Override
        protected void onBindViewHolder(@NonNull IncidenciaViewHolder holder, final int position, @NonNull final Incidencia empresa) {
            holder.departamento.setText(empresa.departamento);
            holder.prioridad.setText(empresa.prioridad);
            holder.motivo.setText(empresa.motivo);

            holder.itemView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Intent intent = new Intent(VerIncidencia.this, VerIncidenciaCompleta.class);
                    intent.putExtra("INCIDENCIA_KEY", getRef(position).getKey());
                    startActivity(intent);
                }
            });
        }

        @Override
        public IncidenciaViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
            View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_incidencia, parent, false);
            return new IncidenciaViewHolder(view);

        }
    };
    recyclerView.setAdapter(mAdapter);
}
}

ViewHolder:

public class IncidenciaViewHolder extends RecyclerView.ViewHolder{
   TextView departamento;
   TextView prioridad;
   TextView motivo;

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

    departamento = itemView.findViewById(R.id.departamento);
    prioridad = itemView.findViewById(R.id.prioridad);
    motivo = itemView.findViewById(R.id.motivo);

   }

}

XML:

<?xml version="1.0" encoding="utf-8"?><android.support.v7.widget.CardView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:cardUseCompatPadding="true">

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal">

    <TextView
        android:id="@+id/departamento"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:gravity="center"
        android:layout_marginTop="-40dp"
        android:textStyle="bold"
        android:textColor="@android:color/black"
        android:textSize="25sp" />

</LinearLayout>

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal">

    <TextView
        android:id="@+id/prioridad"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:gravity="center"
        android:layout_marginTop="30dp"
        android:textColor="@android:color/black"
        android:textSize="25sp" />

</LinearLayout>

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal">

    <TextView
        android:id="@+id/motivo"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:gravity="center"
        android:layout_marginTop="85dp"
        android:textColor="@android:color/black"
        android:textSize="25sp" />

</LinearLayout>

0 个答案:

没有答案