Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/196.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在Android中,试图显示Google日历JSON数据_Android_Json_Google Calendar Api - Fatal编程技术网

在Android中,试图显示Google日历JSON数据

在Android中,试图显示Google日历JSON数据,android,json,google-calendar-api,Android,Json,Google Calendar Api,我的Android应用程序中有一个工作日历。我的目标是从与我的另一个Google帐户关联的日历中将事件添加到此日历。我发现为了让应用程序能够看到事件,我必须公开谷歌日历,这样不仅我的应用程序,而且每个人都可以看到日历。我知道Google日历设置正确,因为我可以从中看到JSON数据。解析JSON数据的URL是:http://www.google.com/calendar/feeds/[我的另一个日历]@gmail.com/public/full。因此,我的问题是如何将这些JSON数据解析到我的应用

我的Android应用程序中有一个工作日历。我的目标是从与我的另一个Google帐户关联的日历中将事件添加到此日历。我发现为了让应用程序能够看到事件,我必须公开谷歌日历,这样不仅我的应用程序,而且每个人都可以看到日历。我知道Google日历设置正确,因为我可以从中看到JSON数据。解析JSON数据的URL是:
http://www.google.com/calendar/feeds/[我的另一个日历]@gmail.com/public/full
。因此,我的问题是如何将这些JSON数据解析到我的应用程序中?我想我必须创建一个JSON解析类,然后在我的日历活动中引用该JSON解析类。下面是我的日历类的样子:`

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.GregorianCalendar;
import java.util.Locale;

import android.app.Activity;
import android.graphics.Color;
import android.os.Bundle;
import android.os.Handler;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.GridView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.Button;
import android.content.Intent;

public class Calendar32View extends Activity {

public GregorianCalendar month, itemmonth;// calendar instances.

public Calendar31Adapter adapter;// adapter instance
public Handler handler;// for grabbing some event values for showing the dot
                        // marker.
public ArrayList<String> items; // container to store calendar items which
                                // needs showing the    event marker
ArrayList<String> event;
LinearLayout rLayout;
ArrayList<String> date;
ArrayList<String> desc;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.cal3_2);
    Locale.setDefault(Locale.US);

    rLayout = (LinearLayout) findViewById(R.id.text);
    month = (GregorianCalendar) GregorianCalendar.getInstance();
    itemmonth = (GregorianCalendar) month.clone();

    items = new ArrayList<String>();

    adapter = new Calendar31Adapter(this, month);

    GridView gridview = (GridView) findViewById(R.id.gridview);
    gridview.setAdapter(adapter);
    handler = new Handler();

    // ---
    //handler.post(calendarUpdater);//--- adds Events
    // ----

    TextView title = (TextView) findViewById(R.id.title);
    title.setText(android.text.format.DateFormat.format("MMMM yyyy", month));

    // --- Previous Month Button
    RelativeLayout previous = (RelativeLayout) findViewById(R.id.previous);
    previous.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            setPreviousMonth();
            refreshCalendar();
        }
    });
    // --- END Previous Month Button

    // --- Next Month Button
    RelativeLayout next = (RelativeLayout) findViewById(R.id.next);
    next.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            setNextMonth();
            refreshCalendar();

        }
    });
    // --- END Next Month Button

    // --- onClick of date ----

    gridview.setOnItemClickListener(new OnItemClickListener() {
        public void onItemClick(AdapterView<?> parent, View v,
                int position, long id) {

            // removing the previous view if added
            if (((LinearLayout) rLayout).getChildCount() > 0) {
                ((LinearLayout) rLayout).removeAllViews();
            }
        }

    });

    // --- END onClick of date ----

}// --- END onCreate

// ---- METHODS ---

protected void setPreviousMonth() {
    if (month.get(GregorianCalendar.MONTH) == month
            .getActualMinimum(GregorianCalendar.MONTH)) {
        month.set((month.get(GregorianCalendar.YEAR) - 1),
                month.getActualMaximum(GregorianCalendar.MONTH), 1);
    } else {
        month.set(GregorianCalendar.MONTH,
                month.get(GregorianCalendar.MONTH) - 1);
    }

}// --- end method

protected void setNextMonth() {
    if (month.get(GregorianCalendar.MONTH) == month
            .getActualMaximum(GregorianCalendar.MONTH)) {
        month.set((month.get(GregorianCalendar.YEAR) + 1),
                month.getActualMinimum(GregorianCalendar.MONTH), 1);
    } else {
        month.set(GregorianCalendar.MONTH,
                month.get(GregorianCalendar.MONTH) + 1);
    }

}// --- END Method

protected void showToast(String string) {
    Toast.makeText(this, string, Toast.LENGTH_SHORT).show();

}// --- end method

public void refreshCalendar() {
    TextView title = (TextView) findViewById(R.id.title);

    adapter.refreshDays();
    adapter.notifyDataSetChanged();

    title.setText(android.text.format.DateFormat.format("MMMM yyyy", month));
}// --- end method



// --- END METHODS -----

}`
导入java.text.DateFormat;
导入java.text.simpleDataFormat;
导入java.util.ArrayList;
导入java.util.GregorianCalendar;
导入java.util.Locale;
导入android.app.Activity;
导入android.graphics.Color;
导入android.os.Bundle;
导入android.os.Handler;
导入android.util.Log;
导入android.view.view;
导入android.view.view.OnClickListener;
导入android.widget.AdapterView;
导入android.widget.AdapterView.OnItemClickListener;
导入android.widget.GridView;
导入android.widget.LinearLayout;
导入android.widget.RelativeLayout;
导入android.widget.TextView;
导入android.widget.Toast;
导入android.widget.Button;
导入android.content.Intent;
公共类日历视图扩展活动{
public gregoriacalendar month,itemmonth;//日历实例。
公共Calendar31Adapter;//适配器实例
public Handler;//用于获取一些事件值以显示点
//马克。
public ArrayList items;//用于存储日历项的容器
//需要显示事件标记
ArrayList事件;
线性布局;
ArrayList日期;
ArrayList desc;
@凌驾
创建时受保护的void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.cal3_2);
setDefault(Locale.US);
rLayout=(LinearLayout)findViewById(R.id.text);
month=(GregorianCalendar)GregorianCalendar.getInstance();
itemmonth=(GregorianCalendar)month.clone();
items=newarraylist();
适配器=新日历适配器(本月);
GridView GridView=(GridView)findViewById(R.id.GridView);
setAdapter(适配器);
handler=新的handler();
// ---
//handler.post(calendarUpdater);//--添加事件
// ----
TextView title=(TextView)findViewById(R.id.title);
title.setText(android.text.format.DateFormat.format(“MMMM-yyyy”,month));
//---上个月按钮
RelativeLayout previous=(RelativeLayout)findViewById(R.id.previous);
previous.setOnClickListener(新的OnClickListener(){
@凌驾
公共void onClick(视图v){
setPreviousMonth();
刷新日历();
}
});
//---上个月结束按钮
//---下个月按钮
RelativeLayout next=(RelativeLayout)findViewById(R.id.next);
setOnClickListener(新的OnClickListener(){
@凌驾
公共void onClick(视图v){
setNextMonth();
刷新日历();
}
});
//---下个月结束按钮
//---点击日期----
setOnItemClickListener(新的OnItemClickListener(){
public void onItemClick(AdapterView父视图、视图v、,
内部位置,长id){
//删除以前的视图(如果已添加)
if(((LinearLayout)rLayout.getChildCount()>0){
((线性布局)rLayout).删除所有视图();
}
}
});
//---单击日期结束----
}//---创建时结束
//----方法---
受保护的void setPreviousMonth(){
if(month.get(gregorianalendar.month)=month
.getActualMinimum(Gregorianalendar.月)){
month.set((month.get(gregorianalendar.YEAR)-1),
月。获取实际最大值(Gregorianalendar.month),1);
}否则{
月.set(gregorianalendar.month,
获取(GregorianCalendar.month)-1);
}
}//---结束方法
受保护的void setNextMonth(){
if(month.get(gregorianalendar.month)=month
.getActualMaximum(Gregorianalendar.月)){
month.set((month.get(gregorianalendar.YEAR)+1),
月。获取实际最小值(Gregorianalendar.month),1);
}否则{
月.set(gregorianalendar.month,
月数(Gregorianalendar.month)+1);
}
}//---结束方法
受保护的void showtoos(字符串){
Toast.makeText(this,string,Toast.LENGTH_SHORT).show();
}//---结束方法
公共日历(){
TextView title=(TextView)findViewById(R.id.title);
adapter.refreshDays();
adapter.notifyDataSetChanged();
title.setText(android.text.format.DateFormat.format(“MMMM-yyyy”,month));
}//---结束方法
//---结束方法-----
}`

我似乎找不到任何关于如何做到这一点的教程。我的目标是SDK 8,这样它就可以在我的2.3.4手机上运行。

Java包含一个类JSONObject:cf:“你可以使用这些方法中的任何一种,比如使用hashMap,比如使用特殊的getString(String键)