0
Hello, I am new to Android programming and am doing a project of which I need to do a CRUD with a litView, anyway, I already have it displaying the data, however I would like to know how I do to get the primary key ID of a record for example, which is being displayed on a listview line from which I clicked. Not the position of the element in listview.
I have already tried to search several examples on the internet and also tried in the English Stack, because they all present methods that take the value of the element’s position in the listview and not the value of Id of the Bank’s information, which does not solve my problem.
For to clarify, I will illustrate a situation: It has two factors, one is the listview line (e.g., position 1); And another is the database record line (e.g., value ID 5) that is being displayed at position 1 of listview.
For I would like to know how I do to get the value 5 (from the Bank ID) by clicking at position 1 of listview.
One of my attempts:
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
String selectedItem = (String) parent.getItemAtPosition(position);
textView.setText("The item you clicked is : " + selectedItem);
}
});
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
textView.setText("The item you clicked is : " + id);
//Or
textView.setText("The item you clicked is: "+position);
}
});
All of them apparently take the position value of the list line, not the Sqlite record ID.