如何获取LinearLayout的id

时间:2014-05-03 13:42:13

标签: android android-linearlayout

这是我的MainActivity抱歉的麻烦

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

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

            // Get the layout for the App Widget and attach an on-click listener 
            // to the button 
            RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.activity_main_widget);

            //Linear layout 
            LinearLayout layout = (LinearLayout)findViewById(R.id.layout1);


            // Create an Intent to launch AppoinTextActivityClass from frontend 
            Intent intent = new Intent(context, AppoinTextActivity.class);
            PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, 0);
            views.setOnClickPendingIntent(R.id.buttonAT, pendingIntent);

            // Create an Intent to launch Day from frontend
            Intent intent1 = new Intent(context, RemindersToday.class);
            PendingIntent pending = PendingIntent.getActivity(context, 0, intent1, 0);
            views.setOnClickPendingIntent(R.id.button2, pending); 

            // Create an Intent to launch Hours from frontend 
            Intent intent2 = new Intent(context, RemindersHour.class);
            PendingIntent pending1 = PendingIntent.getActivity(context, 0, intent2, 0);
            views.setOnClickPendingIntent(R.id.button1, pending1); 

            // Create an Intent to launch Customize from frontend
            Intent intent3 = new Intent(context, ReminderPeriodPicker.class);
            PendingIntent pending2 = PendingIntent.getActivity(context, 0, intent3, 0);
            views.setOnClickPendingIntent(R.id.button3, pending2); 

            appWidgetManager.updateAppWidget(appWidgetId, views);
        } 
      } 
    }

有人可以帮助我如何获得线性布局的ID以及如何从线性布局调用活动。感谢

2 个答案:

答案 0 :(得分:0)

我不确定你是什么意思&#34;从线性布局调用一个活动&#34;,但是为了获得线性布局的id,在你的onCreate中,膨胀xml你&#39;重新使用作为您的应用程序的基本布局。

之类的东西
view = inflater.inflate(R.layout.your_custom_layout);
//be sure that you have defined View view as a global or inside your onCreate.

然后调用线性布局,如

LinearLayout ln = (LinearLayout) view.findViewById(R.id.your_linear_layout)

您需要view.findViewById才能引用LinearLayout所在的父视图

答案 1 :(得分:0)

LinearLayout l1 =(LinearLayout)view.findViewById(R.id.your_linear_layout)