我开发了一个应用程序(称为即时按钮),该应用程序具有小部件功能.此小部件使用PendingIntent作为小部件的onClick.
我的PendingIntent代码是这样的:
Intent active = new Intent(context, InstantWidget.class);
active.setAction(String.valueOf(appWidgetId));
active.putExtra("blabla", blabla); //Some data
PendingIntent actionPendingIntent = PendingIntent.getBroadcast(context, 0, active, 0);
actionPendingIntent.cancel();
actionPendingIntent = PendingIntent.getBroadcast(context, 0, active, 0);
remoteViews.setOnClickPendingIntent(R.id.button, actionPendingIntent);
Run Code Online (Sandbox Code Playgroud)
onReceive获取意图并使用MediaPlayer类做一些重现声音的东西.
我有一些用户的报告说,小部件在一段时间后停止工作,我发现的一些研究是因为任务杀手.看来,当您在TaskKiller中杀死应用程序时,PendingIntent将从内存中删除,因此当您单击该小部件时,它不知道该怎么做.
这有什么解决方案吗?我的代码是错的还是某些东西,或者它是PendingIntent的默认行为?有什么我可以用来避免TaskKiller阻止我的小部件工作?
问候.
如果我在库中为ImageView设置填充,如下所示:
imageView.setPadding(10, 10, 10, 10);
Run Code Online (Sandbox Code Playgroud)
它将在实际设备像素中设置?如何在dip中以编程方式设置填充?
是否可以在TextView中显示复杂的HTML内容?我的HTML将有图像和视频标签.这是可能的还是使用WebView组件还是有一些简单的解决方案?
我有一个列表视图,其中项目有文本视图和按钮.我已经设法在点击工作上进行列表视图onclick和按钮.问题是,当我点击按钮时,我真的不知道它属于哪个列表视图项索引.有什么方法可以知道吗?我需要将它传递给"CRUD"进行编辑等...
我正在给AlertDialog充气让用户发送评论.相当简单.但是我得到了这个Lint警告:
布局使用错误的按钮顺序API> = 14:创建一个相反顺序的layout-v14/chat_comment_dialog.xml文件:取消按钮应该在左边(是"@ string/send | Cancel",应该是"取消| @"字符串/发送")
所以,是的,这是解决方案,为API> = 14创建一个特定的布局并反转顺序.但是....真的吗?这真的是官方的建议吗?在某些设备中设置一个订单而在其他设备中设置不同的订单?作为用户,我会感到非常困惑.我是否应该忽略这个Lint建议,或者以其他方式,对一组设备遵循这种新模式(我认为相当混乱)
无论如何,这是布局:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="8dp" >
<EditText
android:id="@+id/username"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/username"
android:singleLine="true" />
<EditText
android:id="@+id/message"
android:layout_width="match_parent"
android:layout_height="180dp"
android:gravity="top|left"
android:hint="@string/review" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:paddingRight="4dp"
android:text="@string/send"
android:textSize="18sp" />
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:paddingLeft="4dp"
android:text="@android:string/cancel"
android:textSize="18sp" />
</LinearLayout>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
顺便说一下,我必须在XML中而不是在AlertDialog.Builder中膨胀按钮(也许这样按钮会自动自行排序),因为你设置为Builder的deafult按钮的任何onClickListener都会忽略对话框,而我必须避免这种行为来自己控制Dialog.
在iOS上做同样的事情后,我正在为Android开发应用程序.其中一项功能是让用户只需点击一下按钮就可以一个接一个地拨打两个号码.
例如,假设您要拨打1-800-111-1111,然后拨打分机123456.在iOS上,您可以执行以下操作:tel:// 18001111111p123456.
我做了一些挖掘,找不到Android的任何东西.谁能提出任何建议?
一堆谢谢!
我正在编写的应用程序必须向用户显示一个动态创建的EditText小部件表.
我目前的代码:
/**
* Create and display the table of EditTexts on the screen
* @param x Number of columns
* @param y Number of rows
*/
private void createTable(int x, int y) {
TableLayout table = (TableLayout) findViewById(R.id.TableLayout01);
etGrid = new EditText[y][x];
for (int i = 0; i < y; i++) {
TableRow row = new TableRow(this);
for (int j = 0; j < x; j++) {
EditText et = new EditText(this);
et.setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_DECIMAL
| InputType.TYPE_NUMBER_FLAG_SIGNED);
et.setSingleLine();
et.setMinimumWidth(getWindowManager().getDefaultDisplay().getWidth()/x); …Run Code Online (Sandbox Code Playgroud) 我想做的事:
是否有任何现有的小部件执行此操作?如果没有,那么自动(完成/建议)城市名称的好方法是什么?
编辑:我知道AutoCompleteTextView会自动完成.问题更多的是处理城市的详尽数据源(希望在某处可以作为API在线提供),以及将窗口小部件与此数据源列表相关联.
如何在单击主屏幕小部件时打开特定片段,我已经可以打开一个Activity但我不知道如何从小部件打开片段这是我的小部件类
public class MyWidget extends AppWidgetProvider {
ComponentName watchWidget;
RemoteViews remoteViews;
private static final String SYNC_CLICKED = "automaticWidgetSyncButtonClick";
void updateAppWidget(Context context, AppWidgetManager appWidgetManager,
int appWidgetId) {
remoteViews = new RemoteViews(context.getPackageName(), R.layout.My_widgets);
watchWidget = new ComponentName(context, MyWidget.class);
remoteViews.setTextViewText(R.id.appwidget_text,"Widget Example");
// start Activity from the widget
Intent configIntent = new Intent(context, MainActivity.class);
PendingIntent configPendingIntent = PendingIntent.getActivity(context, 0, configIntent, 0);
remoteViews.setOnClickPendingIntent(R.id.widget_container, configPendingIntent);
appWidgetManager.updateAppWidget(watchWidget, remoteViews);
}
Run Code Online (Sandbox Code Playgroud)
那么任何想法?
android ×10
android-widget ×10
animation ×1
geolocation ×1
layer ×1
spinner ×1
telephony ×1
textview ×1
widget ×1