【问题标题】:How to get the id of the LinearLayout如何获取LinearLayout的id
【发布时间】:2014-05-03 13:42:12
【问题描述】:

这是我的 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 以及如何从线性布局中调用活动。谢谢

【问题讨论】:

  • “从线性布局调用活动”是什么意思?

标签: android android-linearlayout


【解决方案1】:

我不确定您所说的“从线性布局调用活动”是什么意思,但是为了获取线性布局的 id,在您的 onCreate 中,膨胀您用作应用程序基本布局的 xml .像

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 所在的父视图

【讨论】:

    【解决方案2】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-10-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-06-30
      • 1970-01-01
      • 1970-01-01
      • 2014-07-12
      相关资源
      最近更新 更多