我有一个成功运行的 appwidget。现在,当手机重新启动时,小部件会丢失所有数据并仅位于主屏幕上。由于我无法在手机重新启动时从广播接收器更新小部件,因此我创建了一个通知,该通知会导致小部件的配置活动。用户再次设置配置并离开配置活动后,一切都不起作用;空闲小部件仍然存在?(用户必须删除小部件并再次创建小部件)。我假设我没有正确接收小部件 id 或者我在广播接收器中做错了,并假设将所有代码移动到onEnable 在小部件方法中?.. 我如何正确刷新小部件。请记住,所有小部件更新都是通过服务完成的。
顺便说一下,我在广播接收器中有这个代码用于 boot_completed 操作:
public void onReceive(final Context context, Intent intent) {
String info = context.getResources().getString(R.string.restart_setting);
int[] allids = AppWidgetManager.getInstance(context).getAppWidgetIds(new ComponentName(context, MyWidgetProvider.class));
for(int appWidgetId:allids){
NotificationManager mnotifyManager = (NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE);
Notification notify = new Notification(R.drawable.icon, "Weather Update", System.currentTimeMillis());
notify.defaults = Notification.DEFAULT_SOUND;
notify.defaults = Notification.DEFAULT_VIBRATE;
Intent Settings = new Intent(context, WidgetConfigure.class);
Settings.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
PendingIntent pending = PendingIntent.getActivity(context, 0, weatherSettings, PendingIntent.FLAG_ONE_SHOT);
notify.setLatestEventInfo(context, "Weather Update", info, pending);
notify.flags = Notification.FLAG_AUTO_CANCEL;
notify.defaults = Notification.DEFAULT_ALL;
mnotifyManager.notify(WEATHER_NOTIFICATION_ID , notify);
}
}
Run Code Online (Sandbox Code Playgroud) 好日子,正如标题所说,任何人都知道如何在片段中从CursorLoader加载数据时实现进度对话框.在这方面找不到任何例子.任何有关如何操作的链接或指南将受到高度赞赏.谢谢
android android-fragments android-dialog android-cursorloader
美好的一天,我在尝试访问包含布局的RelativeLayout视图组时遇到NullPointerexception.在下面的代码中,它被命名为rootlayout.我有这个
date_layout.xml:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/my_layoutroot_id"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#eeeeee"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin">
<TextView
android:id="@+id/date_from1_id"
style="@style/date_text"
android:layout_alignParentTop="true"
android:text="@string/date_from1" />
<TextView
android:id="@+id/date_from2_id"
style="@style/date_text"
android:layout_alignBaseline="@+id/date_from1_id"
android:layout_alignBottom="@+id/date_from1_id"
android:layout_alignParentRight="true"
android:text="@string/date_To1" />
<TextView
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)
并在main_layout.xml中:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<include layout="@layout/date_layout" android:id="@+id/datelayout_id"></include>"
<FrameLayout
android:id="@+id/frame_id"
android:layout_width="match_parent"
android:layout_height="match_parent" >
</FrameLayout>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
我的代码是:
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main_layout);
View view = findViewById(R.id.datelayout_id);
rootlayout = (RelativeLayout)view.findViewById(R.id.my_layoutroot_id);
rootlayout.setOnclickListener(this); // am getting the NullPointerException here
Run Code Online (Sandbox Code Playgroud)
任何想法我可能做错了什么?非常感谢!
美好的一天,我想在将Pojo序列化为json时删除属性名称.我有以下课程
public class Field {
private List<SubFieldItems> subFieldItems;
public List<SubFieldItems> getSubFieldItems() {
return subFieldItems;
}
public void setSubFieldItems(List<SubFieldItems> subFieldItems) {
this.subFieldItems = subFieldItems;
}
}
Run Code Online (Sandbox Code Playgroud)
和SubFieldItems类:
public class SubFieldItems {
@JsonPropertyOrder
private String name;
private List<String> items;
public SubFieldItems(String name, List<String> items) {
this.name = name;
this.items = items;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public List<String> getItems() {
return items;
}
public void setItems(List<String> items) {
this.items = …Run Code Online (Sandbox Code Playgroud) 美好的一天,我在这里有2个问题:
首先是背景信息.
从android文档中,当查询数据库时,我们必须返回一个名为"_id"的列,以便它可以使用游标适配器.现在在我的实现中,假设我有3列"_id","列A""列B".
所以,如果我的数据库表中有8个输入行,那么A列中的前3行将被填充,而B列中的后5行将被填充.如果我在数据库中查询B列并在我的bindview中使用下面的代码,则游标返回所有行,这将导致前3个条目为null,最后5个项目显示在我的gridview图像中.
这是我的bindView:
@Override
public void bindView(View view, Context context, Cursor cursor) {
ViewHolder holder = (ViewHolder)view.getTag();
int columnIndex = cursor.getColumnIndexOrThrow(columnName);
final String name = cursor.getString(columnIndex);
while(cursor.moveToNext()){
if(name != null){
Log.d(TAG, "string name in gridimageadapter is " + name);
BitmapFactory.Options options = new BitmapFactory.Options();
Bitmap bitmap = BitmapFactory.decodeFile(name);
Bitmap newbitmap = Bitmap.createScaledBitmap(bitmap, 200, 200, false);
if(holder.image != null){
holder.image.setImageBitmap(newbitmap);
}
bitmap.recycle();
}
}
}
Run Code Online (Sandbox Code Playgroud)
所以我的问题是:
如何编写sqlite查询以返回行不为空的列?我目前的实施是:
public Cursor retrieveTag(String tag){
String[] condition = {KEY_ID,tag};
Cursor cursor = db.query(DATABASE_TABLE, …Run Code Online (Sandbox Code Playgroud)请好好看看这个.我正在尝试为特定时间和日期设置闹钟.它似乎没有工作,我真的不知道为什么.
Calendar cal = Calendar.getInstance();
cal.setTimeInMillis(System.currentTimeMillis());
cal.set(Calendar.YEAR, mYear);
cal.set(Calendar.MONTH,mMonth);
cal.set(Calendar.DAY_OF_MONTH,mDay);
cal.set(Calendar.HOUR,mHour);
cal.set(Calendar.MINUTE,mMinutes);
// where mYear, mMonths, mDay, mHour and mMinutes are int values from the Date and Time picker dialogs respectively
Intent activate = new Intent(this, Alarm.class);
PendingIntent alarmIntent = PendingIntent.getBroadcast(this, 0, activate, 0);
alarms = (AlarmManager)getSystemService(Context.ALARM_SERVICE);
alarms.set(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(), alarmIntent);
Run Code Online (Sandbox Code Playgroud)
只是为了让你知道,如果我用alerts.set()方法中的System.CurrentTimeInMillis()替换cal.getTimeInMillis(),它就有效.但那显然是我不想要的.谢谢
这里有奇怪的请求,但有没有办法设置一个imageview来保持与另一个imageview相同的drawable,从原始的imageview获取它.我的意思是:
ImageView image1 = new ImageView(this);
image1.setimageResource(R.drawable.blah1);
ImageView image2 = new ImageView(this);
//now i want something like this, which doesn't work. i want to get it from image1
image2.setImageResource(image1.getDrawable());
Run Code Online (Sandbox Code Playgroud)
那么请问我怎样才能从image1实现这个目标?谢谢:)
美好的一天,请想知道如何减少下图中标签和文本框之间的空间,以及如何在标签和框架之间创建一些空格.谢谢.
我的代码:
private void initUI(JFrame parent) {
// private void initUI() {
myPanel = new JPanel(new GridLayout(3,2,1,1));
buttons_panel = new JPanel(new FlowLayout());
username_label = new JLabel("Username: ");
password_label = new JLabel("Password: ");
username = new JTextField(20);
password = new JPasswordField(20);
ok = new JButton("Ok");
ok.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
}
});
cancel = new JButton("Cancel");
cancel.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
dispose();
}
});
myPanel.add(username_label);
myPanel.add(username);
myPanel.add(password_label);
myPanel.add(password);
buttons_panel.add(ok);
buttons_panel.add(cancel);
getContentPane().add(myPanel, BorderLayout.CENTER);
getContentPane().add(buttons_panel, BorderLayout.PAGE_END);
pack(); …Run Code Online (Sandbox Code Playgroud) 好的..首先,我知道非常沮丧的是不在滚动视图中放置列表视图,但这次它不在我的手中,我别无选择.现在,我的Listview项目在达到一定数量时没有显示适配器中的最后几个项目.不是很确定如何解释,但我的意思是作为一个例子,项目来自:1月1日 - 8月22日,列表视图停止在8月15日,1月1日 - 8月17日,它停止在8月10日1月1日 - 3月17日,在3月15日停止,依此类推.
不确定问题是什么..我正在使用自定义Listview,如:
public static void setListViewHeight(ListView listview){
ListAdapter listAdapter = listview.getAdapter();
if(listAdapter == null) {
return;
}
int totalHeight = 0;
// int desiredWidth = MeasureSpec.makeMeasureSpec(listview.getWidth(), MeasureSpec.AT_MOST);
for(int i = 0; i < listAdapter.getCount(); i++) {
View listItem = listAdapter.getView(i, null, listview);
//listItem.measure(desiredWidth, MeasureSpec.UNSPECIFIED);
listItem.measure(0, 0);
totalHeight += listItem.getMeasuredHeight();
}
ViewGroup.LayoutParams params = listview.getLayoutParams();
params.height = totalHeight + (listview.getDividerHeight()*(listAdapter.getCount() - 1)) + totalHeight;
listview.setLayoutParams(params);
//listview.requestLayout();
}
Run Code Online (Sandbox Code Playgroud)
任何人都有像Listview没有显示所有项目的任何问题?...任何想法如何解决这个问题?...提前很感激.
美好的一天,我将是第一个承认,我没有使用片段的经验,只是学习所以请耐心等待我.正如标题所说,我试图将TimePickerDialog的结果设置为我活动中的按钮,但没有成功.当我单击开始按钮时,我看不到通常的TimePickerDialog,我看到的只是屏幕中间的一个小空对话框.那么请问我能做错什么?谢谢.
这是我的代码:
TimeDialog:
public class TimeDialog extends DialogFragment {
private int mHour;
private int mMinute;
public TimeDialog(){
}
public static TimeDialog newInstance(int title){
TimeDialog frag = new TimeDialog();
Bundle args = new Bundle();
args.putInt("title", title);
frag.setArguments(args);
return null;
}
private TimePickerDialog.OnTimeSetListener mTimeSetListener = new TimePickerDialog.OnTimeSetListener() {
@Override
public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
mHour = hourOfDay;
mMinute = minute;
//updateDisplay();
}
/*private void updateDisplay() {
View v = getActivity().getLayoutInflater().inflate(R.layout.add_resp, null);
Button start = (Button)v.findViewById(R.id.start_time_button_id);
start.setText(new StringBuilder().append(mHour).append(":").append(mMinute).toString());
}*/ …Run Code Online (Sandbox Code Playgroud) 美好的一天,基本上我正在寻找一种方法来检索和保存与 sqlite 数据库中的列项目相关的键值对,以便我可以更新列表视图。
示例:如果我有一个名为“group”的列,其中有一个名为“family”的条目;关于该项目,我希望能够为该项目“家庭”保存或检索联系人列表(姓名和号码)。另一个项目条目相同。
什么是最好的方法来做到这一点?我尝试通过 json 使用 Hashmap 的 ArrayList 将联系人详细信息保存在表格的一列中。但这样做有麻烦。我试过这个:
保存时:
//already have the name and number from using the android contacts api
final ArrayList<HashMap<String,String>> contacts = new ArrayList<HashMap<String,String>>();
HashMap<String, String> map = new HashMap<String,String>();
map.put(name, number);
contacts.add(map);
JSONObject json_contacts = new JSONObject();
try {
json_contacts.put("contacts_Arrays", new JSONArray(contacts));
arraylist_to_string = json_contacts.toString();
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
ContentValues values = new ContentValues();
values.put(ContactDB.GROUP, groupname);
values.put(ContactDB.GROUP_CONTACTS, arraylist_to_string);
Log.d(TAG, "Successfully updating contacts for group");
dbadapter.updateGroup(rowId, …Run Code Online (Sandbox Code Playgroud) 我有一个托管片段的活动.按下按钮通过FragmentTransaction从片段A到片段B,并添加到后栈.现在片段B有一个AsyncTask实现,它从一个SD卡加载图像并在加载图像时发布它.如果我按下后退按钮,我的应用程序崩溃..错误报告指示异步任务是问题,因为当按下后退按钮时它仍然加载,所以我的问题是,当按下后退按钮返回到上一个按钮时,我怎么能或在哪里停止AsyncTask片段/活动?..谢谢.
考虑我有一个Optional对象的数组列表,例如List<Visit> visit = {Optional[Visit], Optional[Visit], ...}. 我如何Visit从 获取对象Optional并将这些对象作为 a 返回List?
我尝试过这样的事情:
return Stream.of(visits).filter(value -> Optional.isPresent(value))
.map((Visit t) -> Optional.get(t))
.collect(Collectors.toList());
Run Code Online (Sandbox Code Playgroud)
和这个:
return Stream.of(visits)
.map(visit -> Optional.of(visit).get())
.collect(Collectors.toList());
Run Code Online (Sandbox Code Playgroud)
但这不能编译。
我正在尝试使用Lightweight-Stream-API作为流库。