2014-09-10 112 views
0

如何在右側圖片上的最近時間做一個時間表?對我而言,事實並非如此,我是一名新手。請幫幫我。時間表最近時間

enter image description here --Fragment.java

public class DayFragment extends ListFragment { 
String[] time = new String[] { "06:30","06:40","06:48","06:56","07:04","07:12","07:20","07:28","07:36", "07:44", 
     "07:52", "08:00", "08:08", "08:16", "08:22", "08:31", "08:40", "08:50", "09:00", "09:10", "09:20", 
     "09:30", "09:40", "09:50", "10:00", "10:10", "10:20", "10:30", "10:40", "10:50", "11:00", "11:10", 
     "11:20", "11:30", "11:40", "11:50", "12:00", "12:10", "12:20", "12:30", "12:40", "12:50", "13:00", 
     "13:10", "13:20", "13:30", "13:40", "13:50", "14:00", "14:10", "14:20", "14:30", "14:40", "14:50", 
     "15:00", "15:10", "15:20", "15:30", "15:40", "15:50", "16:00", "16:10", "16:20", "16:30", "16:40", 
     "16:50", "17:00", "17:08", "17:16", "17:24", "17:32", "17:40", "17:48", "17:56", "18:04", "18:12", 
     "18:20", "18:28", "18:36", "18:44", "18:51", "19:00", "19:10", "19:20", "19:30", "19:39", "19:50", 
     "20:03", "20:16", "20:30", "20:43", "20:56", "21:10", "21:23", "21:36", "21:50", "22:03", "22:16", 
     "22:30", "22:43", "22:56", "23:10", "23:23", "23:36"}; 

@Override 
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { 
    View view = inflater.inflate(R.layout.dayfragment, container, false); 
    ArrayAdapter<String> adapter = new ArrayAdapter<String>(getActivity(), 
      android.R.layout.simple_list_item_1, time); 
    setListAdapter(adapter); 
    Time now = new Time(); 
    now.set(now); 
    return view; 
}} 

--fragment.xml

public class DayFragment extends ListFragment { 
String[] time = new String[] { "06:30","06:40","06:48","06:56","07:04","07:12","07:20","07:28","07:36", "07:44", 
     "07:52", "08:00", "08:08", "08:16", "08:22", "08:31", "08:40", "08:50", "09:00", "09:10", "09:20", 
     "09:30", "09:40", "09:50", "10:00", "10:10", "10:20", "10:30", "10:40", "10:50", "11:00", "11:10", 
     "11:20", "11:30", "11:40", "11:50", "12:00", "12:10", "12:20", "12:30", "12:40", "12:50", "13:00", 
     "13:10", "13:20", "13:30", "13:40", "13:50", "14:00", "14:10", "14:20", "14:30", "14:40", "14:50", 
     "15:00", "15:10", "15:20", "15:30", "15:40", "15:50", "16:00", "16:10", "16:20", "16:30", "16:40", 
     "16:50", "17:00", "17:08", "17:16", "17:24", "17:32", "17:40", "17:48", "17:56", "18:04", "18:12", 
     "18:20", "18:28", "18:36", "18:44", "18:51", "19:00", "19:10", "19:20", "19:30", "19:39", "19:50", 
     "20:03", "20:16", "20:30", "20:43", "20:56", "21:10", "21:23", "21:36", "21:50", "22:03", "22:16", 
     "22:30", "22:43", "22:56", "23:10", "23:23", "23:36"}; 

@Override 
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { 
    View view = inflater.inflate(R.layout.dayfragment, container, false); 
    ArrayAdapter<String> adapter = new ArrayAdapter<String>(getActivity(), 
      android.R.layout.simple_list_item_1, time); 
    setListAdapter(adapter); 
    Time now = new Time(); 
    now.set(now); 
    return view; 
}} 

--text_fragment.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:orientation="vertical" 
android:layout_width="match_parent" 
android:gravity="center" 
android:background="#5ba4e5" 
android:layout_height="match_parent"> 
<TextView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:textSize="40px" 
    android:textColor="#040404" 
    android:layout_gravity="center" 
    android:id="@+id/time"/> 

回答

0

她E公司的新手一些僞代碼:

GET your current time -> Time CURRENT_TIME = new Time(); 

現在你必須要找到你time[]的值最接近的時間。那麼,你是想找一份

//exact the same time 
time[index] EQUAL CURRENT_TIME 

OR 

//your current time has to be between your time tables 
time[index] is smaller to CURRENT_TIME && time[index+1] is bigger to CURRENT_TIME 

Time對象,你具備的功能afterbeforecompareJava:Time

小心time[index+1]ArrayOutOfBoundsException索引。此時您必須檢查是否存在time[index+1]。如果沒有,最後一次的價值是你正在尋找的

+0

對我來說並不是結果。你沒有辦法給我例子寫一個源代碼。你寫給我的那個 – user3796282 2014-09-11 09:53:56

+0

,我不明白。 – user3796282 2014-09-11 09:58:02

+0

請幫幫我! =( – user3796282 2014-09-16 10:38:57