-1

こんにちは、特定の日までのカウントダウンを表示するアプリケーションをプログラムしたいと思います。その上で、ウィジェットを提供したいと考えています。メイン アクティビティは問題ありませんが、メイン アクティビティで TextView を参照する方法がわかりません。コードをお見せします(初心者ですみません:))

主要:

public class MainActivity extends Activity {

    private static final String TAG = MainActivity.class.getSimpleName();

    TextView tv;
    long diff;
    long milliseconds;
    long endTime;

    @Override
    public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    Typeface tf = Typeface.createFromAsset(getAssets(), "fonts/PRICEDOW.TTF");
    tv = (TextView)findViewById(R.id.textView1);
    tv.setTypeface(tf);

    SimpleDateFormat formatter = new SimpleDateFormat("dd.MM.yyyy, HH:mm");
    formatter.setLenient(false);

................................................................... ...................................................

ウィジェット:

public class ExampleAppWidgetProvider extends AppWidgetProvider {

    public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
        final int N = appWidgetIds.length;

        Log.i("ExampleWidget",  "Updating widgets " + Arrays.asList(appWidgetIds));

        // Perform this loop procedure for each App Widget that belongs to this provider
        for (int i = 0; i < N; i++) {
            int appWidgetId = appWidgetIds[i];

            // Create an Intent to launch ExampleActivity
            Intent intent = new Intent(context, MainActivity.class);
            PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, 0);
            TextView tu = (TextView) findViewbyId(R.id.textView1);

            // Get the layout for the App Widget 
            RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.widget1);

            // Tell the AppWidgetManager to perform an update on the current app widget
            appWidgetManager.updateAppWidget(appWidgetId, views);
        }
    }
}

ウィジェットのメイン アクティビティからテレビを表示することは可能ですか? :)

ドイツからの多くの挨拶 ;)

4

1 に答える 1