앱을 만들려고하고 있는데 한 목록에서 버스 노선 목록을 정렬하려하지만 버스 경로의 이름을 클릭하면 북쪽/북쪽을 클릭하는 옵션이있는 메시지가 표시됩니다. 남쪽 또는 동쪽/서쪽.두 문자열 배열을 하나의 목록으로 올바른 순서로 정렬하는 방법. - Android
나는 버스 경로를 목록에 넣는 것이 가장 좋은 방법 일뿐만 아니라 클릭 한 항목에 따라 정확한 북/남 또는 동/서에 코드를 작성하는 것이 궁금합니다.
import android.app.AlertDialog;
import android.app.ListActivity;
import android.content.DialogInterface;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;
//import android.widget.Toast;
public class BusRoutes extends ListActivity {
static final String[] BUSROUTES = new String[] {
"01 Kipps Lane/Thompson Road", "02 Dundas", "03 Hailton Rd",
"04 Oxford East", "05 Springbank", "06 Richmond", "07 Wavell",
"08 Riverside", "09 Whitehills", "10 Wonderland", "11 Southcrest",
"11 SouthCrest", "12 Wharncliffe South", "13 Wellington Road",
"13 Highbury", "15 Westmount", "16 Adelaide", "17 Oxford West",
"19 Oakridge", "20 CherryHill", "21 Huron Heights", "22 Trafalgar",
"23 Berkshire", "24 Baseline", "25 Killally", "26 Jalna Blvd West",
"27 Fanshawe College", "28 Lambeth", "30 Newbold",
"31 Orchard Park", "32 Windermere", "33 Proudfoot", "34 Medway",
"35 Argyle", "36 Airport/Industrial", "37 Sovereign Road",
"38 Stoney Creek", "39 Fanshawe West" };
static final String[] BUSROUTES2 = new String[] {
"18 Kipps Lane/Thompson Road", };
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setListAdapter(new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1, BUSROUTES));
getListView().setTextFilterEnabled(true);
}
protected void onListItemClick(ListView l, View v, int position, long id) {
// TODO Auto-generated method stub
super.onListItemClick(l, v, position, id);
new AlertDialog.Builder(this)
.setTitle("Choose Direction")
// Change to display bus times
//.setMessage("from " + getListView().getItemAtPosition(position))
.setPositiveButton("North",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,
int which) {
}
})
.setNeutralButton("South",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,
int which) {
}
}).show();
당신이 "올바른 순서"무엇을 의미합니까? 정렬은 알파벳 순서 또는 번호 순서로 수행 할 수 있습니까? 일부 정렬 알고리즘을 적용하십시오. –
글쎄, 그들은 버스 번호 01 KipsLane..etc와 함께 주문됩니다. 나는 kipslane을 클릭하면 북쪽 또는 남쪽을 말하는 메시지가 나타납니다. 북쪽/남쪽으로가는 모든 버스와 동쪽/서쪽으로가는 하나의 그룹에 대해 두 개의 다른 배열을 하나의 그룹으로 만들어야합니다. 나중에 코딩 작업을 수행하거나 더 좋은 방법이 있습니다. –