カテゴリー:
日記アプリ
閲覧数:410 配信日:2013-10-16 11:12
インポート
▼/DbDiary/src/android/style/system/ActivityTop.java
import java.util.Calendar;
import android.style.systemdb.RecordItem;
プロパティ
public class ActivityTop extends Activity {
private RecordItem Record = null;
// 操作したいアイテムのプロパティを宣言/
private TextView tv_last = null; // 先月
private TextView tv_date = null; // 年月
private TextView tv_next = null; // 翌月
private EditText et_search = null; // 検索窓
private Button btn_top_search = null; // 検索ボタン
private Button btn_top_add = null; // 今日の日記を書くボタン
final Calendar calendar = Calendar.getInstance();//インポートしているCalendarクラスのオブジェクトcalendarを生成
int year = calendar.get(Calendar.YEAR);//現在の年を取得
int month = calendar.get(Calendar.MONTH) + 1;//現在の月を取得。+1する理由はCalendarクラスの月だけ1~12ではなく0~11で表されるため
final int day = calendar.get(Calendar.DAY_OF_MONTH);//現在の月の何日目かを取得
private LinearLayout all = null; // ViewGroupクラス
boolean isWordSearch = false; //DataLoadTaskクラス … doInBackgroundメソッドで、RecordDaoItemクラスlist_search_itemメソッドを呼ぶ際、第2引数で渡す
// Toast制御
private Handler stopToastHandler = new Handler();
private Toast g_Toast = null;
private boolean toastFlag = true;
onCreate()
RecordItemクラスのインスタンスオブジェクトを生成
・アクティビティへビューを追加。予めXMLファイルで作成している配置ビュー読込、表示領域を確保
・この時点でのデータは空
@Override
protected void onCreate(Bundle savedInstanceState) {//引数としてBundleクラスのオブジェクトを受け取る(このアクティビティの 以前の状態が保存されていた場合、このメソッドにはその状態を保持している Bundleオブジェクトが引数として渡される)
super.onCreate(savedInstanceState);//superキーワードを使って、スーパークラスであるActivityオブジェクトのonCreateメソッドを呼び出し、 「onCreate」メソッドをオーバーライド
setContentView(R.layout.top);//アクティビティにビューを追加。配置ビューをXMLファイルで作成しておき、それを読み込んで利用。レイアウト用XMLファイル名が「○○.xml」だった場合には、「R.layout.○○」で参照可能。ここでは、「R.layout.top」で「top.xml」を読込
// どのアイテムを操作するかリソースを割り当て
// findViewById … 引数にリソースIDを指定すると、対応するViewオブジェクトを返す(返り値として対応するViewオブジェクトを受け取るので、いきなり利用可能。オブジェクト生成する必要はない)
// 「ビューに対して割り当てられたリソースID」から、対応するビューオブジェクトを取得(リソースIDから、GUIオブジェクトを取得)
tv_last = (TextView)findViewById(R.id.TextView_last_month);//引数にて別途XMLファイルで作成したレイアウトを表すIDを指定。先月
tv_date = (TextView)findViewById(R.id.TextView_date);//2013/9
tv_next = (TextView)findViewById(R.id.TextView_next_month);//翌月
et_search = (EditText)findViewById(R.id.EditText_top_search);//編集
btn_top_search = (Button)findViewById(R.id.Button_top_search);//検索
btn_top_add = (Button)findViewById(R.id.Button_top_add);//今日の日記を書く
all = (LinearLayout)findViewById(R.id.LinearLayout_all);//画面全体LinearLayout
// ボタンやエディットテキストの初期化
et_search.setFocusable(false);
btn_top_search.setEnabled(false);
// Recordの日付データを初期化
Record = new RecordItem();
Record.setItemSearchNen(String.valueOf(year));
Record.setItemSearchTuki(String.valueOf(month));
// 起動時の1発目は日付で一覧を取得する為、falseに設定
isWordSearch = false;
}
・Stringクラスで用意されているvalueOfメソッドを使って文字列に変換
※valueOfメソッドは引数に指定された値の文字列表現を返す
→RecordItemクラスのプライベートプロパティ「itemsearchnen」「itemsearchtuki」へ、セッターを通じてデータ格納
onResume()
DataLoadTaskクラスのインスタンスオブジェクトを生成
・DataLoadTaskクラス呼出、実行
/**
* アクティビティが前面に来るたびに一覧を更新
*/
@Override
protected void onResume() {
super.onResume();
// 一覧取得タスクの実行
DataLoadTask task = new DataLoadTask();//作成したクラスのインスタンスを作る
task.execute();//起動
}