@Override public void onCreate(Bundle icicle) { super.onCreate(icicle); setContentView(R.layout.activity_gtdeventfolder_listview); ArrayList<Map<String, Object>> items = new ArrayList<Map<String, Object>>(); for (GtdEvent ge : MainControl.gtdEventsOp.events) { HashMap<String, Object> item = new HashMap<String, Object>(); item.put("name", ge.getName()); item.put("status", ge.getEventStatus().toString()); item.put("_id", ge.getId()); items.add(item); } DragNDropListView tlv = (DragNDropListView) getListView(); // adapter = new GtdEventsContentArrayAdapter<GtdEvent>(getApplication() // ,R.layout.gtdevent_item // , MainControl.gtdEventsOp.getEvents(),R.id.grabber); tlv.setDragNDropAdapter( new DragNDropSimpleAdapter( this, items, R.layout.gtdevent_item, new String[] {"name", "status"}, new int[] {R.id.gtdevent_title_textView, R.id.gtdevent_duration_textView}, R.id.grabber)); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_cadastrar); txtDescricao = (EditText) findViewById(R.id.txtDescricao); btnAdicionar = (ImageButton) findViewById(R.id.btnAdicionar); listView = (DragNDropListView) findViewById(android.R.id.list); banco = new Banco(getApplicationContext()); banco.open(); cursor = banco.query(ListaCompras.TABELA); adapter = new DragNDropCursorAdapter( getApplicationContext(), R.layout.rowlayout, cursor, new String[] {ListaCompras.COLUNAS[1]}, new int[] {R.id.text}, R.id.handler); listView.setAdapter(adapter); listView.setOnItemLongClickListener( new AdapterView.OnItemLongClickListener() { @Override public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) { // Pega o Objeto na posição ListaCompras listaCompras = (ListaCompras) listView.getItemAtPosition(position); long resultado = ListaCompras.delete(banco, listaCompras); // Verifica se foi removido com sucesso if (resultado > 0) { Toast.makeText(CadastrarActivity.this, "Removido com sucesso!", Toast.LENGTH_SHORT) .show(); } else { Toast.makeText(CadastrarActivity.this, "Problema ao remover.", Toast.LENGTH_SHORT) .show(); } // Recria a Activity recreate(); return true; } }); btnAdicionar.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { String str = txtDescricao.getText().toString(); if (str == null || str.isEmpty()) { txtDescricao.setError(getString(R.string.msgInsiraDescricao)); } else { ListaCompras listaCompras = new ListaCompras(); listaCompras.setDescricao(str); listItens.add(listaCompras); txtDescricao.setText(""); ListaCompras.insertOrUpdate(banco, listaCompras); // cursor = banco.query(ListaCompras.TABELA); CadastrarActivity.this.recreate(); } } }); }