2012-04-25 6 views
1

下記の画像でカレンダーのようなビューを作成したいが、どこから始めるべきかわからない。私はこれに最善のアプローチを見つけたいと思っています。私はGridViewについて考えましたが、うまくいきませんでした。誰にも何か提案はありますか?カレンダービューを設計する

enter image description here

+0

自分のカレンダーを動作させるためにできることのコンセプトで答えを更新しました。 – AedonEtLIRA

答えて

1

AndroidはSDKにカレンダービューを提供していません。それは開発者の視点からは大きな損失です。 1か月の日を表示し、ユーザがその日を選択するためのオプションを提供することが有益である状況はたくさんあります。

解決策の1つは、サードパーティのコンポーネントを使用することです。もう一つは、これらのリンクをチェックし、あなた自身の

で1を実装するために、あなたがに水平方向のLinearLayoutを取ることができ

http://w2davids.wordpress.com/android-simple-calendar/

この

http://caughtinthemobileweb.wordpress.com/2011/06/20/how-to-implement-calendarview-in-android/

+0

2番目のサンプルコードは私が欲しかったものです。ありがとう – Nishant

2

線形レイアウトのヘッダとグリッドレイアウトを使用。 GridLayoutを使用してクリックコマンドを実装し、派手なアダプタ作業を使用して、曜日/月を管理することができます。

編集:ここでは

はあなたができるとどのようにGridViewのはあなたのために働くだろう何の大まかな概念です。

class CalendarView extends LinearLayout { 

    public CalendarView (Context context) { 
     super(context); 
     setOrientation(LinearLayout.VERTICAL); 

     mHeader = new LinearLayout(context); 
     mHeader.setOrientation(LinearLayout.HORIZONTAL); 
     addView(mHeader); 
     // Add in your days, shouldn't be too bad, they are just text views. 

     mCalendar = new GridView(context); 
     mCalendar.setColumns(mHeader.getNumViews()); // You could hard code this. 
     mCalendar.setAdapterView(new CalendarAdapter()); 
     addView(mCalendar); 
    } 

    // ... Other contructors 


    private class CalendarAdapter extends BaseAdapter { 
     // Override methods, this should be too bad. 

     @Override public view getView (int pos, View convert, ViewGroup parent) { 
      ListView lv = (ListView)convert; 
      if (convert == null) 
       lv = new ListView(parent.getContext()); 

      // Here you will need to figure out some way of 
      // determining the date. 

      CalendarDate app = (CalendarDate)lv.getTag(); 

      // Determine if this view is already set to the correct date, 
      // if not rest the list view 

      app.sort(); 

      lv.setAdapter(new ArrayAdapter(parent.getContext(), R.layout.datelistview, app.getDates()); 
     } 
    } 

    public static class CalendarDate { 
     List<Appointment> mDates = new ArrayList<Appointment>(); 

     public void addAppointment(Appointment app) { 
      mDate.add(app); 
     } 

     // ... and the rest of your methods (getters and state returns) 
    } 

    public Appointment implements Compareable<Appointment> { 
     private Date mDate; 

     private String mName; // Appointment name 
     private String mDesc; // Appointment description 

     @Override public int compareTo(Appointment to) { 
      return mDate.compareTo(mDate); 
      } 
    } 
} 
+0

お返事ありがとうございました。私はカレンダーの日付にいくつかのイベントをマークすることができるカレンダーを探していました。 Avi Kumar Mankuが提供するリンクから、私が探していたソリューションを提供するサンプルコードを入手しました。あなたは非常に支持的でした。 – Nishant

0

あなたに役立つだろうです同じ重さのすべてのテキストビューを含む垂直LinearLayout。

android:layout_weight="1" 

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:orientation="vertical" 
    android:padding="5dp"> 

    <LinearLayout 
     android:id="@+id/linearLayout1" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:orientation="horizontal" > 

     <TextView 
      android:id="@+id/textView1" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:text="sun" /> 

     <TextView 
      android:id="@+id/textView2" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:text="mon" /> 

     <TextView 
      android:id="@+id/textView3" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:text="tue" /> 

     <TextView 
      android:id="@+id/textView4" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:text="wed" /> 

     <TextView 
      android:id="@+id/textView5" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:text="thu" /> 

     <TextView 
      android:id="@+id/textView6" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:text="fri" /> 
     <TextView 
      android:id="@+id/textView7" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:text="sat" /> 
    </LinearLayout> 
    <LinearLayout 
     android:id="@+id/linearLayout1" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:orientation="horizontal" > 

     <TextView 
      android:id="@+id/textView1" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:text="sun" /> 

     <TextView 
      android:id="@+id/textView2" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:text="mon" /> 

     <TextView 
      android:id="@+id/textView3" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:text="tue" /> 

     <TextView 
      android:id="@+id/textView4" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:text="wed" /> 

     <TextView 
      android:id="@+id/textView5" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:text="thu" /> 

     <TextView 
      android:id="@+id/textView6" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:text="fri" /> 
     <TextView 
      android:id="@+id/textView7" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:text="sat" /> 
    </LinearLayout> 

</LinearLayout> 
+0

Agarwalの答えについての私のコメントを参照してください。 – AedonEtLIRA

関連する問題