How to get record ID that is populated in ListView

1

How do I get the ListView ID? Here is my summarized code:

UPDATE

How do I get the LOG ID that is populated by SQLite in the ListView.

public class MainActivity extends ActionBarActivity {
    private SQLiteDatabase database;
    private SimpleCursorAdapter dataSource;     

    private static final String[] campos = {"nomeObjeto", "nomePessoa", "_id"};

    ListView listView;
    BaseDAO helper;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        listView = (ListView) findViewById(R.id.lvObjetosEmprestados);

        helper = new BaseDAO(this);     
        database = helper.getWritableDatabase();
        AtualizarObjetos();
    }   


    public void AtualizarObjetos(){ 
       dataSource = new SimpleCursorAdapter(this, R.layout.objetosemprestadosrow, objetosEmprestados, campos, new int [] {R.id.lblNomeObjeto, R.id.lblEmprestadoPara});
       listView.setAdapter(dataSource);         
    }
}
    
asked by anonymous 04.02.2014 / 16:52

2 answers

2

I suppose you are referring to the ID of the record that corresponds to the line that is clicked.

For this you need to declare and assign a OnItemClickListener to ListView

listView.setOnItemClickListener(new OnItemClickListener() {

    @Override
    public void onItemClick(AdapterView<?> a, View v, int pos, long id) {

        // id é o valor que você procura
    }
});
    
04.02.2014 / 17:07
0

By its code the id is R.id.lvObjectsBuild. But you can pick up using this function that every view has: listView.getId ();

Remembering that R.id.lvObjectedObjects must be in the activity_main layout and be in a listview. Otherwise it will break.

    
04.02.2014 / 16:57