I am creating a project but I am not able to open the listView item, I am already inserting and editing, but I can only open the last created item, for example I have 10 items in the list, only the last one I create independent of which I click opens always the same. if I delete the last created only the previous one it opens. create in the list, test, test1 and test 2. click on any of them and always open the same. I would like to know how I can do to open the item clicked with its content, because only when I click I can delete or edit. What I need to implement is the OneList at the end of DAOideia
insira o código aqui
List.class
public class ListaIdeia extends ActionBarActivity{
private ListView listView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_lista_ideia);
this.listView = (ListView)findViewById(R.id.listView);
ArrayList<Ideia> lista = new DAOIdeia(this).buscar();
IdeiaAdapter ideiaAdapter = new IdeiaAdapter(this,lista);
this.listView.setAdapter(ideiaAdapter);
this.listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapter, View view, int p, long id) {
if(p < 200) {
Intent segundaActivity = new Intent(ListaIdeia.this, DetalhesIdeia.class);
startActivity(segundaActivity);
}
}
});
DAOIdeia.class
public class DAOIdeia {
private SQLiteDatabase db;
public DAOIdeia(Context context){
this.db = new SQLiteCore(context).getWritableDatabase();
}
public void insert(Ideia ideia){
ContentValues valores = new ContentValues();
valores.put("nome",ideia.getNome());
valores.put("descricao",ideia.getDescricao());
this.db.insert("ideia",null,valores);
}
public void update(Ideia ideia){
ContentValues valores = new ContentValues();
valores.put("nome",ideia.getNome());
valores.put("descricao",ideia.getDescricao());
this.db.update("ideia",valores,"_id = ?",new String[]{""+ideia.get_id()});
}
public void delete(Ideia ideia){
this.db.delete("ideia","_id = ?",new String[]{""+ideia.get_id()});
}
public ArrayList<Ideia> buscar(){
ArrayList<Ideia> lista = new ArrayList<>();
String[] colunas = new String[]{"_id","nome","descricao"};
Cursor cursor = this.db.query("ideia",colunas,null,null,null,null,"nome DESC");
if (cursor.getCount() >0){
cursor.moveToFirst();
do{
Ideia ideia = new Ideia();
ideia.set_id(cursor.getInt(0));
ideia.setNome(cursor.getString(1));
ideia.setDescricao(cursor.getString(2));
lista.add(ideia);
}while(cursor.moveToNext());
}
return lista;
}
public ArrayList<Ideia> listaUma(){
ArrayList<Ideia> lista = new ArrayList<>();
String[] colunas = new String[]{"_id","nome","descricao"};
Cursor cursor = this.db.query("ideia",colunas,null,null,null,null,"nome DESC");
if (cursor.getCount() >0) {
Ideia ideia = new Ideia();
ideia.set_id(cursor.getInt(0));
ideia.setNome(cursor.getString(1));
ideia.setDescricao(cursor.getString(2));
lista.add(ideia);
}
return lista;
}
Part that creates the ArrayList
public class DetalhesIdeia extends ActionBarActivity {
private ListView listView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_lista_ideia);
this.listView = (ListView) findViewById(R.id.listView);
ArrayList<Ideia> lista = new DAOIdeia(this).listaUma();
IdeiaAdapterEdit IdeiaAdapterEdit = new IdeiaAdapterEdit(this, lista);
this.listView.setAdapter(IdeiaAdapterEdit);
}
}