Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to set my listview in date order?
    primarykey
    data
    text
    <p>I have three Java classes: <code>classetitulo</code>, <code>adaptertitulos</code> and <code>titulo</code>.</p> <p>This is the code from <code>classtitulo</code>:</p> <pre><code>public class classetitulo { private String documento; private String vencimento; private Double valor; public classetitulo() { } public classetitulo(String documento, String vencimento, Double valor) { this.documento = documento; this.vencimento = vencimento; this.valor = valor; } public boolean getVencido() { boolean vencido = false; SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd"); Date datahora = null; try { datahora = (Date) formatter.parse(this.vencimento); } catch (ParseException e) { // TODO Auto-generated catch block e.printStackTrace(); } Date now = new Date(); if(datahora.compareTo(now) &lt; 0 ) { vencido = true; } return vencido; } public String getVencimento() { return vencimento; } public void setVencimento(String vencimento) { this.vencimento = vencimento; } public String getDocumento() { return documento; } public void setDocumento(String documento) { this.documento = documento; } public Double getValor() { return valor; } public void setValor(Double valor) { this.valor = valor; } } </code></pre> <p>And this is the one from <code>adaptertitulo</code>:</p> <pre><code>public class adaptertitulo extends ArrayAdapter&lt;classetitulo&gt; { public SQLiteDatabase db; Cursor c; dadossistema ds; /* * Used to instantiate layout XML file into its corresponding View objects */ private final LayoutInflater inflater; /* * each list item layout ID */ private final int resourceId; public List&lt;String&gt; selecionados = new ArrayList&lt;String&gt;(); public adaptertitulo(Context context, int resource, List&lt;classetitulo&gt; listatitulos) { super(context, resource, listatitulos); this.inflater = LayoutInflater.from(context); this.resourceId = resource; } @Override public View getView(int position, View convertView, ViewGroup parent) { //get the person from position classetitulo person = getItem(position); // get a new View no matter recycling or ViewHolder FIXME convertView = inflater.inflate(resourceId, parent, false); //get all object from view TextView documento = (TextView) convertView.findViewById(R.id.tvDOCUMENTOtitulo); TextView vencimento = (TextView) convertView.findViewById(R.id.tvVENCIMENTOtitutlo); TextView valor = (TextView) convertView.findViewById(R.id.tvVALORtitulo); documento.setText(person.getDocumento()); vencimento.setText(person.getVencimento()); valor.setText(person.getValor().toString()); vencimento.setTextColor(Color.GRAY); //SimpleDateFormat format = new SimpleDateFormat("dd-MM-yyyy"); //vencimento.setText(format.format(person.getVencimento())); SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd"); Date datahora = null; try { datahora = (Date) formatter.parse(person.getVencimento()); } catch (ParseException e) { // TODO Auto-generated catch block e.printStackTrace(); } Date now = new Date(); if(datahora.compareTo(now) &lt; 0 ) { documento.setTextColor(Color.RED); vencimento.setTextColor(Color.RED); valor.setTextColor(Color.RED); }else if(datahora == now) { documento.setTextColor(Color.YELLOW); vencimento.setTextColor(Color.YELLOW); valor.setTextColor(Color.YELLOW); }else { documento.setTextColor(Color.GREEN); vencimento.setTextColor(Color.GREEN); valor.setTextColor(Color.GREEN); } DecimalFormat decFormat = new DecimalFormat("##,###,###,##0.00"); valor.setText(decFormat.format(person.getValor())); //valor.setTextColor(Color.GRAY); /* if(person.getValor() &lt;= 0.0) valor.setTextColor(Color.parseColor("#CD853F")); documento.setTextColor(Color.WHITE); if(person.getEmOferta()) descricao.setTextColor(Color.parseColor("#98FB98")); return convertView; */ return convertView; } } </code></pre> <p>and the <code>titulo</code> ListView:</p> <pre><code>private void ListarTitulos() { // TODO Auto-generated method stub Button bVenc = (Button) findViewById(R.id.bVenc); Button baVenc = (Button) findViewById(R.id.baVenc); Button bTotaltit = (Button) findViewById(R.id.bTotaltit); String[] campo = new String[] {"documento", "vencimento", "valor"}; final List&lt;classetitulo&gt; listatitulos = new ArrayList&lt;classetitulo&gt;(); db = openOrCreateDatabase(ds.getNomeBanco(), Context.MODE_WORLD_WRITEABLE, null); c = db.query( "titulos", campo, null, null, null, null, null); c.moveToFirst(); Double vencidos = 0.0; Double avencer = 0.0; if(c.getCount() &gt; 0) { while(true) { classetitulo titulo = new classetitulo(); titulo.setDocumento(c.getString(c.getColumnIndex("documento")).toString()); titulo.setVencimento(c.getString(c.getColumnIndex("vencimento")).toString()); try { titulo.setValor(Double.parseDouble(c.getString(c.getColumnIndex("valor")))); } finally {} if(titulo.getVencido()) vencidos = vencidos + Double.parseDouble(c.getString(c.getColumnIndex("valor"))); else avencer = avencer + Double.parseDouble(c.getString(c.getColumnIndex("valor"))); listatitulos.add(titulo); if(!c.moveToNext()) break; } } c.close(); db.close(); DecimalFormat decFormat = new DecimalFormat("##,###,###,##0.00"); //valor.setText(decFormat.format(person.getValor())); String a = decFormat.format(vencidos); String b = decFormat.format(avencer); String c = String.valueOf(vencidos + avencer); Double d = Double.valueOf(c); String e = decFormat.format(d); bVenc.setText(a); baVenc.setText(b); bTotaltit.setText(e); ListView lv = (ListView) findViewById(R.id.lvtitulos); ArrayAdapter&lt;classetitulo&gt; adpterTitulos; adpterTitulos = new adaptertitulo(this, R.layout.rowlisttitulo, listatitulos); lv.setAdapter(adpterTitulos); } </code></pre> <p>I need to set the ListView in titulo.java into date order, with the old date first, then actual/beyond date at last. The <code>vendcimento</code> is the date.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload