我从我的服务器获取搜索结果,并在列表视图中显示它们。首先,我需要将其更改为可滚动下拉菜单。下拉列表中的值格式为: SchoolA;俄罗斯 我需要在点击时捕获此文本并将其分为SchoolA和俄罗斯。 代码是在活动页面如下:编写方法来处理点击在列表视图android
private void populateResults(String response) {
List<String> resultsFromServer = parseResponse(response);
ListView resultsList = (ListView) findViewById(R.id.schoolssListView);
ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(getApplicationContext(), android.R.layout.simple_list_item_1, resultsFromServer);
resultsList.setAdapter(arrayAdapter);
addListenerOnClick(); // this is the method in which i need the above mentioned operations}
现在,在列表视图的XML页面代码如下:
<ListView
android:id="@+id/schoolssListView"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
</ListView>
这不就是一个列表吗?它不会成为搜索框的下拉菜单。 – user2791805
对于下拉菜单,您应该保留一个按钮和一个listView –
也可以请告诉如何在该位置的文本上使用stringsplit方法? – user2791805