BroadcastReceiverの内部では、リストがダウンロードされるたびに、そしてそれが最後にテキストビューを更新したいたびに追跡します。私は次のことをしましたが、時間が表示されません。
@Override
public void onReceive(Context context, Intent intent) {
_context = context;
Toast.makeText(context, "ListDownloadReceiver....", Toast.LENGTH_SHORT)
.show();
boolean force = intent.getBooleanExtra("FORCE", false);
long nextUpdateTime = getUpdateTime();
if (force || nextUpdateTime < System.currentTimeMillis()) {
if (isNetworkAvailable()) {
Log.i(LIST_DOWNLOAD_RECEIVER,
"Going to be downloading the list...");
DownloadListData downloadList = new DownloadListData(context);
downloadList.execute();
} else {
Log.i(LIST_DOWNLOAD_RECEIVER, "Not connected...");
context.registerReceiver(this, new IntentFilter(
ConnectivityManager.CONNECTIVITY_ACTION));
}
}
DatabaseHandler db = DatabaseHandler.getInstance(context);
String timeFormat = "d/M/yyyy 'at' k:mm:ss";
long lastUpdate = Long.valueOf(db.getPreference("LAST_UPDATED_TIME",
"0"));
CharSequence time = DateFormat.format(timeFormat, lastUpdate);
Log.i(LIST_DOWNLOAD_RECEIVER, "Time is: " + time);
LayoutInflater inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View view = inflater.inflate(R.layout.activity_main, null);
TextView tv = (TextView) view.findViewById(R.id.lastRefreshed);
tv.append("Blah: " + time);
}
これは私の.xmlファイルです
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="left|top"
android:orientation="vertical" >
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/noShowsLayout"
android:layout_width="match_parent"
android:layout_height="115dp"
android:orientation="horizontal"
android:background="@color/blue" >
<TextView
android:id="@+id/noShowsTextView"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:gravity="center"
android:text="@string/no_added_shows"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textSize="18dip" />
</LinearLayout>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:orientation="horizontal" >
<ListView
android:id="@+id/listView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
</ListView>
</LinearLayout>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="48dp"
android:layout_gravity="bottom"
android:background="@color/blue"
android:orientation="horizontal" >
<ImageButton
android:id="@+id/refreshButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="left"
android:contentDescription="@string/refresh"
android:src="@drawable/refresh"/>
<TextView
android:id="@+id/lastRefreshed"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_gravity="center"
android:layout_marginLeft="5dp"
android:text="@string/lastRefreshTime"
android:textAppearance="?android:attr/textAppearanceSmall" />
<ImageButton
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:contentDescription="@string/remove_tv_show"
android:src="@drawable/content_discard"
android:clickable="false"/>
</LinearLayout>
</LinearLayout>