2014-09-10 3 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

그녀를 전자는 초보자를위한 몇 가지 의사 코드입니다 :

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

지금 당신은 당신의 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 

당신이 after, beforecompare (Java:Time)

time[index+1]ArrayOutOfBoundsException 조심 기능을 가지고있는 인덱스를 찾고 있습니다. 이 시점에서 time[index+1]이 있는지 확인해야합니다. 그렇지 않다면 마지막 시간 값은 찾고있는 값입니다.

+0

나를위한 것이 아닙니다. 당신은 소스 코드를 작성하는 예제가 내게 없었습니다. – user3796282

+0

당신이 저를 썼다는 것을 이해하지 못했습니다. – user3796282

+0

제발, 도와주세요 !!! = ( – user3796282