1

私はGoogleドキュメントや他の多くのサイトをフォローし、カレンダーのプログラミングを行いましたが、Android API v14未満のデバイスでは機能しません... API v10を超えるすべてのデバイスをサポートできるカレンダーAPIのコードを誰でも提供できますか....

MainActivity.java

package com.test.weekly;
import java.text.Format;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.database.Cursor;
import android.os.Bundle;
import android.provider.CalendarContract;
import android.text.format.DateFormat;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;

@SuppressLint("NewApi")
public class MainActivity extends Activity implements OnClickListener{

private Cursor mCursor = null;
private static final String[] COLS = new String[] { CalendarContract.Events.TITLE, CalendarContract.Events.DTSTART};

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    mCursor = getContentResolver().query(CalendarContract.Events.CONTENT_URI, COLS, null, null, null);
    mCursor.moveToFirst();
    Button b = (Button)findViewById(R.id.next);
    b.setOnClickListener(this);
    b = (Button)findViewById(R.id.previous);
    b.setOnClickListener(this);
    onClick(findViewById(R.id.previous));
}
@Override
public void onClick(View v) {
    TextView tv = (TextView)findViewById(R.id.data);
    String title = "N/A";
    Long start = 0L;
    switch(v.getId()) {
    case R.id.next:
        if(!mCursor.isLast()) mCursor.moveToNext();
        break;
    case R.id.previous:
        if(!mCursor.isFirst()) mCursor.moveToPrevious();
        break;
    }
    Format df = DateFormat.getDateFormat(this);
    Format tf = DateFormat.getTimeFormat(this);
    try {
        title = mCursor.getString(0);
        start = mCursor.getLong(1);
    } catch (Exception e) {
        //ignore
    }
    tv.setText(title+" on "+df.format(start)+" at "+tf.format(start));
}

}

4

1 に答える 1

1

Android has undocumented Calendar API that is supported on older devices.

This is a tiny class to provide limited support of android Calendar. You can look into sources to understand how to work with Android calendar using undocumented API.

Complete project for Eclipse is here.

If you can read russian (or use translate.google.com), you can read this topic.

于 2013-06-17T08:25:40.297 に答える