2010年10月12日火曜日

ArryaList

ArrayListを使って、アイコン+Text2行分の情報を複数回表示するようにしてみる。

・ArrayAdapter<>には、データをTextViewのtextにセットして、Activityで表示が出来る
・ArrayAdapterをオーバーライドして自分の出力したい形式に変更する。

ということなので、連絡帳からユーザ名と誕生日情報を取得用に
ContactAdapterを作成しました。
ArrayAdapter"contactsstatus"のcontactsstatusは自分で作成したリストです。
ユーザ名と誕生日をリスト化しています。
public class ContactAdapter extends ArrayAdapter<ContactsStatus> {
private LayoutInflater inflater;
public ContactAdapter(Context context, int textViewResourceId,
List<ContactsStatus> items) {
super(context, textViewResourceId, items);
this.inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
// ビューを受け取る
View view = inflater.inflate(R.layout.contactsname, null);
// データの取得
ContactsStatus item = getItem(position);
if (item != null) {
// ユーザ名をセット
TextView displayName = (TextView) view.findViewById(R.id.ContactsName);
displayName.setTypeface(Typeface.DEFAULT_BOLD);
displayName.setText(item.getDisplayName());
// 誕生日情報をビューにセット
TextView birthday = (TextView) view.findViewById(R.id.Birthday);
birthday.setText(item.getBirth());
}
return view;
}
}

開発初心者の自分へ友人からのアドバイスをもらいました。

とりあえず開発をしていたんだけど、どうやら適当に書きすぎていたようで、
以下のことに注意してみたほうが良い、と指摘をいただきました。

1.Warningは放置しない
 →不具合の元なので対処しましょう、とのこと。
2.ArrayList<E>みたいなののEの部分はちゃんと指定すること(ジェネリックでぐぐれ)
 →<>自体記載しなくても動いてたので書いてなかったんだけれど、
  入力している型があっていないときに指摘してくれるらしい。
3.APIは、意味がわからなくてもとりあえず眺める(いつかわかる日がくる)
 →頑張りましょう。
4.変数名が適切じゃない場合が多いのでこまめにリファクタリングする
 →Androidの場合、非スタティックフィールドはmから変数名を始める必要がある。
5.Control+Spaceで入力保管とCommand+Shift+Rでリソース選択は重要
 →Eclipseの機能です。超便利なので手癖に出来るようにしましょう。
6.ArrayListなどの代入先はListなどの大きな単位の型に入れた方が後々楽になる場面が。
 →ArrayListはListの中に含まれているため、大きな単位での記載が可能らしいです。

2010年10月6日水曜日

Google Calendar で新しくカレンダーを作成する方法

まだ不明。
でもCreating new calendarsに以下の説明がある。

To create a new calendar, first create the Atom or JSON-C code for a calendar <entry> element or data object like the ones in the previous example. For example, you might create the following code to represent a calendar to keep track of your Little League team:

{
  "data": {
    "title": "Little League Schedule",
    "details": "This calendar contains the practice schedule and game times.",
    "timeZone": "America/Los_Angeles",
    "hidden": false,
    "color": "#2952A3",
    "location": "Oakland"
  }
}



ここらへんいじれば何とかなるのかなー?



2010年10月4日月曜日

Google Calendar からの情報取得

Google Calendarから自分が持ってるカレンダーの一覧を取得できた!

以下のサイトが役に立ったよ!
【Working with the Android Calendar】
http://www.developer.com/ws/article.php/3850276/Working-with-the-Android-Calendar.htm&rurl=translate.google.co.jp&twu=1&usg=ALkJrhjUYAeZzDVZgnpWXwImDY38cUjA7w

【Android Developersのディスカッションより】
http://groups.google.co.jp/group/android-developers/msg/3ab354642cc7438e