how to find the position of item in a AutoCompletetextview filled with Array
I have an array (array1 with States) and AutoCompleteTextview in which I'm filling it with array1. When I select the value from AutocompleteTextView I select a state from AutoCompleteTextView Dropdown
What I want is to get the position of the item from array1 which I've selected.
What I've tried is OnClickEvent of AutocompelteTextView.
STATE.setOnItemClickListener(new OnItemClickListener(){
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long rowId) {
String selection = (String) parent.getItemAtPosition(position);
String num = selection;
}
});
It ss giving me the value which I selected from dropdown but i want to get the position of the value in array1. For Example I have an array of size 4, like array1 = {A,B,C,D}, and if I select B it should return me B position in Array i.e 2.
I hope I made it clear. Thanks in advance.
add a comment |
I have an array (array1 with States) and AutoCompleteTextview in which I'm filling it with array1. When I select the value from AutocompleteTextView I select a state from AutoCompleteTextView Dropdown
What I want is to get the position of the item from array1 which I've selected.
What I've tried is OnClickEvent of AutocompelteTextView.
STATE.setOnItemClickListener(new OnItemClickListener(){
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long rowId) {
String selection = (String) parent.getItemAtPosition(position);
String num = selection;
}
});
It ss giving me the value which I selected from dropdown but i want to get the position of the value in array1. For Example I have an array of size 4, like array1 = {A,B,C,D}, and if I select B it should return me B position in Array i.e 2.
I hope I made it clear. Thanks in advance.
You can use int position variable for the position of the value in onItemClick Listener.
– Chirag
Nov 29 '12 at 8:41
Item.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { //// id contains item if from database ItemNoSelected = id; } }); --- here id is id from database
– Vijay
Jul 7 '15 at 6:57
add a comment |
I have an array (array1 with States) and AutoCompleteTextview in which I'm filling it with array1. When I select the value from AutocompleteTextView I select a state from AutoCompleteTextView Dropdown
What I want is to get the position of the item from array1 which I've selected.
What I've tried is OnClickEvent of AutocompelteTextView.
STATE.setOnItemClickListener(new OnItemClickListener(){
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long rowId) {
String selection = (String) parent.getItemAtPosition(position);
String num = selection;
}
});
It ss giving me the value which I selected from dropdown but i want to get the position of the value in array1. For Example I have an array of size 4, like array1 = {A,B,C,D}, and if I select B it should return me B position in Array i.e 2.
I hope I made it clear. Thanks in advance.
I have an array (array1 with States) and AutoCompleteTextview in which I'm filling it with array1. When I select the value from AutocompleteTextView I select a state from AutoCompleteTextView Dropdown
What I want is to get the position of the item from array1 which I've selected.
What I've tried is OnClickEvent of AutocompelteTextView.
STATE.setOnItemClickListener(new OnItemClickListener(){
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long rowId) {
String selection = (String) parent.getItemAtPosition(position);
String num = selection;
}
});
It ss giving me the value which I selected from dropdown but i want to get the position of the value in array1. For Example I have an array of size 4, like array1 = {A,B,C,D}, and if I select B it should return me B position in Array i.e 2.
I hope I made it clear. Thanks in advance.
edited Sep 9 '13 at 11:01
Emil Sierżęga
1,04722129
1,04722129
asked Nov 29 '12 at 8:39
raghav chopra
4942725
4942725
You can use int position variable for the position of the value in onItemClick Listener.
– Chirag
Nov 29 '12 at 8:41
Item.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { //// id contains item if from database ItemNoSelected = id; } }); --- here id is id from database
– Vijay
Jul 7 '15 at 6:57
add a comment |
You can use int position variable for the position of the value in onItemClick Listener.
– Chirag
Nov 29 '12 at 8:41
Item.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { //// id contains item if from database ItemNoSelected = id; } }); --- here id is id from database
– Vijay
Jul 7 '15 at 6:57
You can use int position variable for the position of the value in onItemClick Listener.
– Chirag
Nov 29 '12 at 8:41
You can use int position variable for the position of the value in onItemClick Listener.
– Chirag
Nov 29 '12 at 8:41
Item.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { //// id contains item if from database ItemNoSelected = id; } }); --- here id is id from database
– Vijay
Jul 7 '15 at 6:57
Item.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { //// id contains item if from database ItemNoSelected = id; } }); --- here id is id from database
– Vijay
Jul 7 '15 at 6:57
add a comment |
5 Answers
5
active
oldest
votes
Use the position variable in the onItemClick.
STATE.setOnItemClickListener(new OnItemClickListener(){
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long rowId) {
String selection = (String) parent.getItemAtPosition(position);
int pos = -1;
for (int i = 0; i < yourarray.length; i++) {
if (yourarray[i].equals(selection)) {
pos = i;
break;
}
}
System.out.println("Position " + pos); //check it now in Logcat
}
});
this does not give me correct position i want the position of Variable from Array but it gives the position from the AutocompleteDropdown i see
– raghav chopra
Nov 29 '12 at 10:15
@raghavchopra, check the edited answer
– Ram kiran
Nov 29 '12 at 10:20
But what if it is not Array instead it is ArrayList<String>
– raghav chopra
Nov 29 '12 at 12:31
Well i think i can do that
– raghav chopra
Nov 29 '12 at 12:43
5
Problem is is there are two identical names in the autocomplete.
– Marlon
Oct 28 '16 at 12:05
|
show 2 more comments
Use List instead of Array. Implement onItemClickListener for AutoCompleteTextView, then use indexOf on your list to find the index of selected item.
actvCity.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
long arg3) {
int index = cityNames.indexOf(actvCity.getText().toString());
// Do Whatever you want to do ;)
}
});
add a comment |
@Override
public void onItemClick(AdapterView<?> parent, View view,int position, long id)
{
TextView txtvw=(TextView) view;
String str=txtvw.getText().toString();
int index = contactNames.indexOf(str);
}
add a comment |
Item.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
//// id contains item if from database
ItemNoSelected = id;
}
});
id is from database, we can use that
add a comment |
You can find the parent string in the clickItem listener.
OSchools in this case is the custom ArrayList.
Object item = parent.getItemAtPosition(position);
for(OSchools d : data){
Log.e("name",d.getName());
String name = d.getName();
if(d.getName() != null && name.contains(item.toString())){
ID = d.getID();
}
1
An answer based only on code it's not considered a proper SO answer. Could you add explanation for your code? (from review)
– FrankS101
Nov 22 at 18:53
Sorry, update the answer
– Gerardo Salazar Sánchez
Nov 22 at 18:58
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f13621762%2fhow-to-find-the-position-of-item-in-a-autocompletetextview-filled-with-array%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
5 Answers
5
active
oldest
votes
5 Answers
5
active
oldest
votes
active
oldest
votes
active
oldest
votes
Use the position variable in the onItemClick.
STATE.setOnItemClickListener(new OnItemClickListener(){
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long rowId) {
String selection = (String) parent.getItemAtPosition(position);
int pos = -1;
for (int i = 0; i < yourarray.length; i++) {
if (yourarray[i].equals(selection)) {
pos = i;
break;
}
}
System.out.println("Position " + pos); //check it now in Logcat
}
});
this does not give me correct position i want the position of Variable from Array but it gives the position from the AutocompleteDropdown i see
– raghav chopra
Nov 29 '12 at 10:15
@raghavchopra, check the edited answer
– Ram kiran
Nov 29 '12 at 10:20
But what if it is not Array instead it is ArrayList<String>
– raghav chopra
Nov 29 '12 at 12:31
Well i think i can do that
– raghav chopra
Nov 29 '12 at 12:43
5
Problem is is there are two identical names in the autocomplete.
– Marlon
Oct 28 '16 at 12:05
|
show 2 more comments
Use the position variable in the onItemClick.
STATE.setOnItemClickListener(new OnItemClickListener(){
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long rowId) {
String selection = (String) parent.getItemAtPosition(position);
int pos = -1;
for (int i = 0; i < yourarray.length; i++) {
if (yourarray[i].equals(selection)) {
pos = i;
break;
}
}
System.out.println("Position " + pos); //check it now in Logcat
}
});
this does not give me correct position i want the position of Variable from Array but it gives the position from the AutocompleteDropdown i see
– raghav chopra
Nov 29 '12 at 10:15
@raghavchopra, check the edited answer
– Ram kiran
Nov 29 '12 at 10:20
But what if it is not Array instead it is ArrayList<String>
– raghav chopra
Nov 29 '12 at 12:31
Well i think i can do that
– raghav chopra
Nov 29 '12 at 12:43
5
Problem is is there are two identical names in the autocomplete.
– Marlon
Oct 28 '16 at 12:05
|
show 2 more comments
Use the position variable in the onItemClick.
STATE.setOnItemClickListener(new OnItemClickListener(){
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long rowId) {
String selection = (String) parent.getItemAtPosition(position);
int pos = -1;
for (int i = 0; i < yourarray.length; i++) {
if (yourarray[i].equals(selection)) {
pos = i;
break;
}
}
System.out.println("Position " + pos); //check it now in Logcat
}
});
Use the position variable in the onItemClick.
STATE.setOnItemClickListener(new OnItemClickListener(){
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long rowId) {
String selection = (String) parent.getItemAtPosition(position);
int pos = -1;
for (int i = 0; i < yourarray.length; i++) {
if (yourarray[i].equals(selection)) {
pos = i;
break;
}
}
System.out.println("Position " + pos); //check it now in Logcat
}
});
edited Sep 9 '13 at 11:01
Emil Sierżęga
1,04722129
1,04722129
answered Nov 29 '12 at 8:43
Ram kiran
17.8k114874
17.8k114874
this does not give me correct position i want the position of Variable from Array but it gives the position from the AutocompleteDropdown i see
– raghav chopra
Nov 29 '12 at 10:15
@raghavchopra, check the edited answer
– Ram kiran
Nov 29 '12 at 10:20
But what if it is not Array instead it is ArrayList<String>
– raghav chopra
Nov 29 '12 at 12:31
Well i think i can do that
– raghav chopra
Nov 29 '12 at 12:43
5
Problem is is there are two identical names in the autocomplete.
– Marlon
Oct 28 '16 at 12:05
|
show 2 more comments
this does not give me correct position i want the position of Variable from Array but it gives the position from the AutocompleteDropdown i see
– raghav chopra
Nov 29 '12 at 10:15
@raghavchopra, check the edited answer
– Ram kiran
Nov 29 '12 at 10:20
But what if it is not Array instead it is ArrayList<String>
– raghav chopra
Nov 29 '12 at 12:31
Well i think i can do that
– raghav chopra
Nov 29 '12 at 12:43
5
Problem is is there are two identical names in the autocomplete.
– Marlon
Oct 28 '16 at 12:05
this does not give me correct position i want the position of Variable from Array but it gives the position from the AutocompleteDropdown i see
– raghav chopra
Nov 29 '12 at 10:15
this does not give me correct position i want the position of Variable from Array but it gives the position from the AutocompleteDropdown i see
– raghav chopra
Nov 29 '12 at 10:15
@raghavchopra, check the edited answer
– Ram kiran
Nov 29 '12 at 10:20
@raghavchopra, check the edited answer
– Ram kiran
Nov 29 '12 at 10:20
But what if it is not Array instead it is ArrayList<String>
– raghav chopra
Nov 29 '12 at 12:31
But what if it is not Array instead it is ArrayList<String>
– raghav chopra
Nov 29 '12 at 12:31
Well i think i can do that
– raghav chopra
Nov 29 '12 at 12:43
Well i think i can do that
– raghav chopra
Nov 29 '12 at 12:43
5
5
Problem is is there are two identical names in the autocomplete.
– Marlon
Oct 28 '16 at 12:05
Problem is is there are two identical names in the autocomplete.
– Marlon
Oct 28 '16 at 12:05
|
show 2 more comments
Use List instead of Array. Implement onItemClickListener for AutoCompleteTextView, then use indexOf on your list to find the index of selected item.
actvCity.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
long arg3) {
int index = cityNames.indexOf(actvCity.getText().toString());
// Do Whatever you want to do ;)
}
});
add a comment |
Use List instead of Array. Implement onItemClickListener for AutoCompleteTextView, then use indexOf on your list to find the index of selected item.
actvCity.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
long arg3) {
int index = cityNames.indexOf(actvCity.getText().toString());
// Do Whatever you want to do ;)
}
});
add a comment |
Use List instead of Array. Implement onItemClickListener for AutoCompleteTextView, then use indexOf on your list to find the index of selected item.
actvCity.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
long arg3) {
int index = cityNames.indexOf(actvCity.getText().toString());
// Do Whatever you want to do ;)
}
});
Use List instead of Array. Implement onItemClickListener for AutoCompleteTextView, then use indexOf on your list to find the index of selected item.
actvCity.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
long arg3) {
int index = cityNames.indexOf(actvCity.getText().toString());
// Do Whatever you want to do ;)
}
});
answered Nov 18 '14 at 8:58
SANAT
3,7592442
3,7592442
add a comment |
add a comment |
@Override
public void onItemClick(AdapterView<?> parent, View view,int position, long id)
{
TextView txtvw=(TextView) view;
String str=txtvw.getText().toString();
int index = contactNames.indexOf(str);
}
add a comment |
@Override
public void onItemClick(AdapterView<?> parent, View view,int position, long id)
{
TextView txtvw=(TextView) view;
String str=txtvw.getText().toString();
int index = contactNames.indexOf(str);
}
add a comment |
@Override
public void onItemClick(AdapterView<?> parent, View view,int position, long id)
{
TextView txtvw=(TextView) view;
String str=txtvw.getText().toString();
int index = contactNames.indexOf(str);
}
@Override
public void onItemClick(AdapterView<?> parent, View view,int position, long id)
{
TextView txtvw=(TextView) view;
String str=txtvw.getText().toString();
int index = contactNames.indexOf(str);
}
edited May 14 '15 at 13:07
answered May 14 '15 at 5:30
Jasmine John
44457
44457
add a comment |
add a comment |
Item.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
//// id contains item if from database
ItemNoSelected = id;
}
});
id is from database, we can use that
add a comment |
Item.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
//// id contains item if from database
ItemNoSelected = id;
}
});
id is from database, we can use that
add a comment |
Item.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
//// id contains item if from database
ItemNoSelected = id;
}
});
id is from database, we can use that
Item.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
//// id contains item if from database
ItemNoSelected = id;
}
});
id is from database, we can use that
answered Jul 7 '15 at 6:59
Vijay
1,06731633
1,06731633
add a comment |
add a comment |
You can find the parent string in the clickItem listener.
OSchools in this case is the custom ArrayList.
Object item = parent.getItemAtPosition(position);
for(OSchools d : data){
Log.e("name",d.getName());
String name = d.getName();
if(d.getName() != null && name.contains(item.toString())){
ID = d.getID();
}
1
An answer based only on code it's not considered a proper SO answer. Could you add explanation for your code? (from review)
– FrankS101
Nov 22 at 18:53
Sorry, update the answer
– Gerardo Salazar Sánchez
Nov 22 at 18:58
add a comment |
You can find the parent string in the clickItem listener.
OSchools in this case is the custom ArrayList.
Object item = parent.getItemAtPosition(position);
for(OSchools d : data){
Log.e("name",d.getName());
String name = d.getName();
if(d.getName() != null && name.contains(item.toString())){
ID = d.getID();
}
1
An answer based only on code it's not considered a proper SO answer. Could you add explanation for your code? (from review)
– FrankS101
Nov 22 at 18:53
Sorry, update the answer
– Gerardo Salazar Sánchez
Nov 22 at 18:58
add a comment |
You can find the parent string in the clickItem listener.
OSchools in this case is the custom ArrayList.
Object item = parent.getItemAtPosition(position);
for(OSchools d : data){
Log.e("name",d.getName());
String name = d.getName();
if(d.getName() != null && name.contains(item.toString())){
ID = d.getID();
}
You can find the parent string in the clickItem listener.
OSchools in this case is the custom ArrayList.
Object item = parent.getItemAtPosition(position);
for(OSchools d : data){
Log.e("name",d.getName());
String name = d.getName();
if(d.getName() != null && name.contains(item.toString())){
ID = d.getID();
}
edited Nov 22 at 18:58
answered Nov 22 at 16:34
Gerardo Salazar Sánchez
4915
4915
1
An answer based only on code it's not considered a proper SO answer. Could you add explanation for your code? (from review)
– FrankS101
Nov 22 at 18:53
Sorry, update the answer
– Gerardo Salazar Sánchez
Nov 22 at 18:58
add a comment |
1
An answer based only on code it's not considered a proper SO answer. Could you add explanation for your code? (from review)
– FrankS101
Nov 22 at 18:53
Sorry, update the answer
– Gerardo Salazar Sánchez
Nov 22 at 18:58
1
1
An answer based only on code it's not considered a proper SO answer. Could you add explanation for your code? (from review)
– FrankS101
Nov 22 at 18:53
An answer based only on code it's not considered a proper SO answer. Could you add explanation for your code? (from review)
– FrankS101
Nov 22 at 18:53
Sorry, update the answer
– Gerardo Salazar Sánchez
Nov 22 at 18:58
Sorry, update the answer
– Gerardo Salazar Sánchez
Nov 22 at 18:58
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f13621762%2fhow-to-find-the-position-of-item-in-a-autocompletetextview-filled-with-array%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
You can use int position variable for the position of the value in onItemClick Listener.
– Chirag
Nov 29 '12 at 8:41
Item.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { //// id contains item if from database ItemNoSelected = id; } }); --- here id is id from database
– Vijay
Jul 7 '15 at 6:57