开发者

How can I pass a string through an inner class without finalizing it

开发者 https://www.devze.com 2023-02-06 17:46 出处:网络
I have implemented a ListView and want the OnClickListener to use the long id parameter (ie. which item from the list was clicked) to index the String[] that I am populating the list from, so that I c

I have implemented a ListView and want the OnClickListener to use the long id parameter (ie. which item from the list was clicked) to index the String[] that I am populating the list from, so that I can pass that String ie. the text of the specific item I clicked. I would make it final but that would be an issue as I need to repopulate this list later on in the lifecycle of the program (which you might say can't be done with a string, I will proba开发者_开发百科bly switch to a StringBuilder[] but if anyone has advice on this part feel free). I hope this is not confusing, to give some elaboration on what I am doing, I am populating a ListView from a String[] gathered from a mysql database and then I am going to later sort the list based on proximity (obtained from GPS position) so because the id for the listitem will be different for each person I am going to pass the text string that makes up the item in the list that was clicked on, so using item id alone is not feasible, because the item id for an individual list (that has been re-sorted) will be useless to the server. Can anyone advise me on how to make this possible or a potential work around?


Don't use OnClickListener with a ListView. Use AdapterView.OnItemSelectedListener. When you override its onItemSelected (AdapterView parent, View view, int position, long id) method, you get the ListView, the View that was clicked on in the list, its position and its id as parameters. If the list is just TextViews, like with a normal ArrayAdapter, you can just use view.getText().toString() to get the String out.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号