3

連絡先同期アダプターを作成しました。それはすべて正常に機能していますが、もう1つ必要です。何らかの理由で同期が正常に完了しない場合、同期が失敗したときに Google アカウントが表示されているようなメッセージを表示したい

スクリーンショット

4

2 に答える 2

7

解決策は、同期結果に遅延を設定することでした。この遅延の後、同期が再開されます。

try {
    DO THE SYNCHRONIZATION
} catch (AuthenticationException e) {
    Log.e(TAG, "AuthenticationException");
    syncResult.stats.numAuthExceptions++;
    syncResult.delayUntil = 180;
} catch (ParseException e) {
    Log.e(TAG, "ParseException");
    syncResult.stats.numParseExceptions++;
} catch (IOException e) {
    Log.e(TAG, "IOException");
    syncResult.stats.numIoExceptions++;
    syncResult.delayUntil = 180;
}
于 2013-02-12T10:07:46.167 に答える
-3

あなたが欲しいのはトーストだと思います

シンプルトースト:

Toast.makeText(context, text, duration).show();

textご想像のとおり、表示したいテキストです。 durationToast.LENGTH_SHORTまたはToast.LENGTH_LONGのいずれかです(トーストサールが表示される時間によって異なります)

トーストの画像を使用したより複雑なアプローチ:(sync_toast_lo.xml)

<?xml version="1.0" encoding="utf-8"?>
  <RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/SynctoastLayout"
    android:background="@android:color/black">

  <ImageView
    android:layout_height="wrap_content"
    android:layout_width="fill_parent"
    android:src="@drawable/your_logo"
    android:layout_toLeftOf="@+id/textView"
    android:layout_margin="5dip"
    android:id="@+id/syncLogo">
  </ImageView>

  <TextView
    android:id="@+id/syncFailedText"
    android:layout_height="wrap_content"
    android:layout_width="fill_parent"
    android:text="The sync has failed!"
    android:gravity="center"
    android:textColor="@android:color/white">
  </TextView>
</RelativeLayout>

そしてあなたのコードでは:

LayoutInflater inflater = getLayoutInflater();
View view = inflater.inflate(R.layout.Sync_toast_lo,
                               (ViewGroup) findViewById(R.id.SynctoastLayout));

Toast toast = new Toast(this);
toast.setView(view);
toast.show();
于 2013-02-12T09:30:02.167 に答える