How to get Bank Date Sqlite on Android and format in dd-mm-yyyy, using viewHolder? [closed]

1
public class ContatoArrayAdapter extends ArrayAdapter<Contato> {

    private int resource = 0;
    private LayoutInflater inflater;
    private Context context;

    public ContatoArrayAdapter(Context context, int resource) {
        super(context, resource);
        inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        this.resource = resource;
        this.context = context;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        View view = null;
        ViewHolder viewHolder = null;

        if (convertView == null) {
            viewHolder = new ViewHolder();

            view = inflater.inflate(resource, parent, false);

            viewHolder.txtCor = (ImageView) view.findViewById(R.id.txtCor);
            viewHolder.txtNome = (TextView) view.findViewById(R.id.txtNome);
            viewHolder.txtTelefone = (TextView) view.findViewById(R.id.txtTelefone);

            view.setTag(viewHolder);

            convertView = view;

        } else {
            viewHolder = (ViewHolder) convertView.getTag();
            view = convertView;
        }

        Contato contato = getItem(position);

//        if (contato.getNome().toUpperCase().startsWith("A"))
//            viewHolder.txtCor.setBackgroundColor( context.getResources().getColor(R.color.azul) );
//        else
//            if (contato.getNome().toUpperCase().startsWith("B"))
//                viewHolder.txtCor.setBackgroundColor(context.getResources().getColor(R.color.vermelho));
//            else
//                viewHolder.txtCor.setBackgroundColor(context.getResources().getColor(R.color.color1));
        viewHolder.txtNome.setText(contato.getNome());
            viewHolder.txtTelefone.setText(contato.getDatasEspeciais().toString());

        return view;

    }

    static class ViewHolder {

        ImageView txtCor;
        TextView txtNome;
        TextView txtTelefone;
    }
}

    
asked by anonymous 29.06.2017 / 08:25

2 answers

0

You can use SimpleDateFormat . Here's an example:

SimpleDateFormat formatter = new SimpleDateFormat("EEEE, MMM dd, yyyy HH:mm:ss a");
try {
    Date date = formatter.parse("Friday, Jun 7, 2013 12:10:56 PM");
    Log.wtf("TAG", new SimpleDateFormat("dd-MM-yyyy").format(date));

} catch (ParseException e) {
    e.printStackTrace();
}

To adapt to your case, simply subscribe "Friday, Jun 7, 2013 12:10:56 PM" to contato.getDatasEspeciais().toString() , however you need to check exactly what format of your date is not fully visible. Here are some examples below that I found in this answer :

"yyyy.MM.dd G 'at' HH:mm:ss z"  2001.07.04 AD at 12:08:56 PDT
"EEE, MMM d, ''yy"  Wed, Jul 4, '01
"h:mm a"    12:08 PM
"hh 'o''clock' a, zzzz" 12 o'clock PM, Pacific Daylight Time
"K:mm a, z" 0:08 PM, PDT
"yyyyy.MMMMM.dd GGG hh:mm aaa"  02001.July.04 AD 12:08 PM
"EEE, d MMM yyyy HH:mm:ss Z"    Wed, 4 Jul 2001 12:08:56 -0700
"yyMMddHHmmssZ" 010704120856-0700
"yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"   2001-07-04T12:08:56.235-0700
"yyyy-MM-dd'T'HH:mm:ss.SSSXXX"   2001-07-04T12:08:56.235-07:00
"YYYY-'W'ww-u"  2001-W27-3
    
29.06.2017 / 14:05
0

You can recover this way: 1) parse () String to Date

2) format () that Date to String

String formattedDate = suavariavel.format(new SimpleDateFormat("yyyy-MM-dd hh:mm:ss").parse(messageGSON.getCreated()));
viewHolder.textViewMessageDate.setText(formattedDate);

Visit this link: link

    
29.06.2017 / 14:25