小编cho*_*how的帖子

如何在"包含"布局中访问Button

请参阅doc:http://android-developers.blogspot.com/2009/02/android-layout-tricks-2-reusing-layouts.html

我在包含的布局中有一个按钮,我该如何访问按钮?我不知道id!如何定义OnClickListener ...?

请帮忙...

layout android onclick include

36
推荐指数
3
解决办法
4万
查看次数

布局问题:如何在顶部和底部放置一些东西?

我想创建一个布局,顶部和底部有一个水平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)

有人可以告诉你吗?请帮忙.

layout android android-linearlayout

8
推荐指数
1
解决办法
3万
查看次数

两种方法之间更新Android App Widget有什么区别?

我在网上/书中读到了一些关于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()吗?怎么样?

android widget broadcastreceiver android-appwidget

5
推荐指数
1
解决办法
832
查看次数

未知品牌的Android USB供应商ID

请参阅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应用程序吗?

请指教.

debugging usb sdk android

5
推荐指数
2
解决办法
6275
查看次数