如何在TextView中设置当前日期

时间:2017-04-25 09:52:25

标签: android date image-uploading

我需要在图像上传操作到db时在我的UI中设置当前日期。我在Adapter上的上传按钮代码和片段上的方法。我该如何调用代码?再次,我只需要在我的应用程序中显示当前日期。谢谢

enter image description here

  public MyViewHolder(View view) {
        super(view);

        input_tgl = (TextView) view.findViewById(R.id.input_tgl_terima);
        String dateApp = new SimpleDateFormat("dd-MMM-yyyy").format(new Date());
        final String strDateApp = dateApp.replaceAll("-", " ");

3 个答案:

答案 0 :(得分:1)

试试这个:

//in your fragment
public static YourFragment fragment;

onCreate{
fargment = YourFragment.this;
}
public void updaDate(){
 YourTextView.setText("");
}


in your adapter
YourFragment.fragment.updateDate();

答案 1 :(得分:0)

找到解决方案

Calendar c = Calendar.getInstance();
String formattedDate = df.format(c.getTime());

yourTextview.setText(formattedDate );

答案 2 :(得分:0)

所以基本上你想从Adapter类调用fragment方法,因为你可以做任何这个......

解决方案1:使适配器成为片段的内部类,以便您可以直接调用该方法。

解决方案2:更新适配器构造函数以接受Fragment作为参数。

类似的东西:

customAdapter = new CustomAdapter(myContext, list, HomeFragment.this);

并更新适配器的构造函数:

public CustomAdapter(Context context, int id, HomeFragment fragment) {
    this.fragment = fragment;
}

然后使用片段变量调用方法。

fragment.updateDate();
相关问题