请参阅doc:http://android-developers.blogspot.com/2009/02/android-layout-tricks-2-reusing-layouts.html
我在包含的布局中有一个按钮,我该如何访问按钮?我不知道id!如何定义OnClickListener ...?
请帮忙...
我想创建一个布局,顶部和底部有一个水平LinearLayout,中间有一个ListView填充.
我该如何定义main.xml.
我尝试在顶部创建一个水平LinearLayout的布局,底部是TextView,中间是ListView填充; 没关系.但在我将底部TextView修改为LinearLayout后,底部的LinearLayout消失了.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
>
<TextView
android:textSize="12px"
android:text="something here"
android:layout_width="50px"
android:layout_height="wrap_content"
/>
<TextView
android:textSize="12px"
android:text="something here"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
</LinearLayout>
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="bottom"
>
<ListView
android:id="@+id/listbody"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
<LinearLayout
android:orientation="horizontal"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
>
<TextView
android:layout_height="wrap_content"
android:layout_width="0dip"
android:layout_weight="1"
android:textSize="12px"
android:text="50%"
/>
<TextView
android:layout_height="wrap_content"
android:layout_width="0dip"
android:layout_weight="1"
android:textSize="12px"
android:text="50%"
/>
</LinearLayout>
</LinearLayout>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
有人可以告诉你吗?请帮忙.
我在网上/书中读到了一些关于App Widget的例子,更新小部件的正常例子是onUpdate(Context context, AppWidgetManager appWidgetManager,int[] appWidgetIds)
AppWidgetProvider的方法,如下所示:
final int N = appWidgetIds.length;
for (int i=0; i<N; i++) {
int appWidgetId = appWidgetIds[i];
RemoteViews updateViews = new RemoteViews(context.getPackageName(), R.layout.mywidget_layout);
updateViews.setTextViewText(R.id.mytext, "updated text");
appWidgetManager.updateAppWidget(appWidgetId, updateViews);
}
Run Code Online (Sandbox Code Playgroud)
它会循环更新每个小部件.
但是现在,我必须实现一个App Widget,它在BroadcastReceiver onReceive(Context context, Intent intent)
方法中更新,因为没有传入int [] appWidgetIds.所以我实现了这样的代码:
RemoteViews updateViews = new RemoteViews(context.getPackageName(), R.layout.mywidget_layout);
updateViews.setTextViewText(R.id.mytext, "updated text");
ComponentName myComponentName = new ComponentName(context, AndroidBatteryWidgetProvider.class);
AppWidgetManager manager = AppWidgetManager.getInstance(context);
manager.updateAppWidget(myComponentName, updateViews);
Run Code Online (Sandbox Code Playgroud)
它没有逐个更新小部件,但实际上所有小部件都立即更新.即使它按我的意愿工作,但我很困惑为什么不需要像以前一样逐个更新所有小部件.
两种方法有什么区别?
我可以发送另一个广播BroadcastReceiver.onReceive()
来触发AppWidgetProvider.onUpdate()
吗?怎么样?
请参阅http://developer.android.com/guide/developing/device.html#VendorIds,我想购买一个未知品牌的Android设备,例如http://app-4-android.blogspot.com/2011/ 09/ainol-novo-8-android-22-8-in-tablet.html,我如何获得USB供应商ID?它可以用来开发Android应用程序吗?
请指教.