以下代码:
Calendar now = Calendar.getInstance();
month = now.get(Calendar.MONTH) + 1;
year = now.get(Calendar.YEAR);
System.out.println("Month " + month + " year " + year);
SimpleDateFormat dt1 = new SimpleDateFormat("MMMM YYYY");
e.setMonthnYear(dt1.format(now.getTime()));
Run Code Online (Sandbox Code Playgroud)
在服务器上部署后显示以下异常:
java.lang.IllegalArgumentException: Illegal pattern character 'Y'
java.text.SimpleDateFormat.compile(SimpleDateFormat.java:768)
java.text.SimpleDateFormat.initialize(SimpleDateFormat.java:575)
java.text.SimpleDateFormat.<init>(SimpleDateFormat.java:500)
java.text.SimpleDateFormat.<init>(SimpleDateFormat.java:475)
iland.employee.EmployeeAction.fetchAllAtted(EmployeeAction.java:169)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
java.lang.reflect.Method.invoke(Method.java:597)
Run Code Online (Sandbox Code Playgroud)
在我使用的本地主机上JDK v1.8,上面的代码工作正常,但在服务器上它无法正常工作.
我该如何解决这个问题?
为什么RelativeLayout替换为ConstraintLayoutandroid空活动的默认布局文件.我需要知道为什么要使用ConstraintLayout它,它为我们提供了什么其他好处.
我有一个ObservableCollection,我可以添加和删除集合中的项目.但我无法替换集合中的现有项目.有一种方法可以替换项目并将其反映在我的绑定组件上.
System.Collections.Specialized.NotifyCollectionChangedAction.Replace
Run Code Online (Sandbox Code Playgroud)
任何人都可以告诉我如何做到这一点?
我想打开WhatsApp一个特定的对话,并用一些字符串填充文本字段.
我拥有的代码和我设法与联系人打开对话:
private void openConversationWithWhatsapp(String e164PhoneNumber){
String whatsappId = e164PhoneNumber+"@s.whatsapp.net";
Uri uri = Uri.parse("smsto:" + whatsappId);
Intent intent = new Intent(Intent.ACTION_SENDTO, uri);
intent.setPackage("com.whatsapp");
intent.putExtra(Intent.EXTRA_TEXT, "text");
intent.putExtra(Intent.EXTRA_SUBJECT, "subject");
intent.putExtra(Intent.EXTRA_TITLE, "title");
intent.putExtra(Intent.EXTRA_EMAIL, "email");
intent.putExtra("sms_body", "The text goes here");
intent.putExtra("text","asd");
intent.putExtra("body","body");
intent.putExtra("subject","subjhect");
startActivity(intent);
}
Run Code Online (Sandbox Code Playgroud)
但是文本框中没有内容.我试图查看AndroidManifest.xml文件内部并找到有关其对话活动的以下信息:
<activity android:theme="@style/Theme.App.CondensedActionBar" android:name="com.whatsapp.Conversation" android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize" android:windowSoftInputMode="stateUnchanged">
<intent-filter>
<action android:name="android.intent.action.SENDTO" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="sms" />
<data android:scheme="smsto" />
</intent-filter>
</activity>
Run Code Online (Sandbox Code Playgroud)
有人知道额外使用吗?他们故意阻止这个吗?我在他们的FAQ页面中看到了他们的iOS API .
如果您在移动电话上使用Chrome Mobile 查看我的网站并向任何方向滚动,则页脚将无法保留.对原因或修复有任何想法吗?
页脚的CSS代码如下所示:
#footer{
width:100%;
height:auto;
filter:...;
margin:0;
padding:0;
position:fixed;
bottom:0;
z-index:3000;
}
Run Code Online (Sandbox Code Playgroud)
最初显示的页脚部分是#pull2,具有以下CSS属性:
#pull2 {
width: 100%;
display: block;
position:static;
float:none;
padding-left:10px;
z-index:0;
background: ...;
background-position:...;
cursor:pointer;
}
#pull2 p{
line-height: 40px;
margin:0;
}
Run Code Online (Sandbox Code Playgroud) 我已经检查了从Android应用程序中创建新日历的方法.我见过的唯一方法是在最新的api版本中使用新的Calendar API,但这只是在您使用时似乎有效CalendarContract.ACCOUNT_TYPE_LOCAL.它不会让您创建附加到用户Google帐户的日历,与之同步Google Calendar.它不会出现在Google日历的在线日历列表中.
values.put(CalendarContract.Calendars.ACCOUNT_TYPE,
CalendarContract.ACCOUNT_TYPE_LOCAL);
Run Code Online (Sandbox Code Playgroud)
我已尝试使用帐户中的帐户类型,但这不起作用.但它似乎没有产生任何错误.结果很好.
values.put(CalendarContract.Calendars.ACCOUNT_TYPE, accountType);
Run Code Online (Sandbox Code Playgroud)
以下是使用Calendar APIand SYNCADAPTER(帐户类型已注释掉)添加新本地日历的完整代码.有谁知道我想做的事情是否可能?
AccountManager manager = AccountManager.get(context);
Account[] accounts = manager.getAccountsByType("com.google");
String accountName = "";
String accountType = "";
for (Account account : accounts) {
accountName = account.name;
accountType = account.type;
break;
}
ContentResolver cr = context.getContentResolver();
ContentValues values = new ContentValues();
values.put(CalendarContract.Calendars.ACCOUNT_NAME, accountName);
//values.put(CalendarContract.Calendars.ACCOUNT_TYPE, accountType);
values.put(CalendarContract.Calendars.ACCOUNT_TYPE, CalendarContract.ACCOUNT_TYPE_LOCAL);
values.put(CalendarContract.Calendars.NAME, DaysSince.CAL_NAME);
values.put(CalendarContract.Calendars.CALENDAR_DISPLAY_NAME, DaysSince.CAL_NAME);
values.put(CalendarContract.Calendars.SYNC_EVENTS, 1);
values.put(CalendarContract.Calendars.VISIBLE, 1);
values.put(CalendarContract.Calendars.CALENDAR_ACCESS_LEVEL, CalendarContract.Calendars.CAL_ACCESS_OWNER);
values.put(CalendarContract.Calendars.OWNER_ACCOUNT, accountName);
values.put(CalendarContract.Calendars.DIRTY, 1);
values.put(CalendarContract.Calendars.CALENDAR_TIME_ZONE, …Run Code Online (Sandbox Code Playgroud) 下面的代码滚动4页就好了.我的问题是onPageScrolled滚动页面时不会触发事件.无论我是否使用该myPager.SetOffsccreenPageLimit(4)命令,都会发生这种情况.阅读文档之后,我的理解是,当我implements ViewPager.OnPageChangeListener在MyPagerAdapter课程中包含事件应该被触发时.我究竟做错了什么?
谢谢,加里布莱克利
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
MyPagerAdapter adapter = new MyPagerAdapter();
ViewPager myPager = (ViewPager) findViewById(R.id.mysevenpanelpager);
myPager.setAdapter(adapter);
myPager.setCurrentItem(0);
myPager.setOffscreenPageLimit(4);
}
private class MyPagerAdapter extends PagerAdapter
implements ViewPager.OnPageChangeListener {
public int getCount() {
return 4;
}
public Object instantiateItem(View collection, int position) {
LayoutInflater inflater = (LayoutInflater) collection.getContext()
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
int resId = 0;
switch (position) {
case 0:
resId = R.layout.left;
break;
case 1:
resId = R.layout.gps;
break;
case …Run Code Online (Sandbox Code Playgroud) 这可能看起来很简单,但我还不知道如何去做。
当用户单击域 url 时,我需要打开我的应用程序。我需要将 URL 与没有路径的域 (android:host) 匹配。example.com 或 example.com/
我让它在 example.com/ 上工作(带斜杠),但我无法在没有斜杠的情况下捕获 URL:example.com
我尝试使用 pathPattern /*,它也不起作用。
以下是我的 Android 清单:
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="http" />
<data android:scheme="https" />
<data android:host="example.com" />
<data android:host="www.example.com" />
<data android:pathPattern="/*" />
<data android:path="/" />
</intent-filter>
Run Code Online (Sandbox Code Playgroud)
简单地说,我希望匹配带有或不带有结尾斜杠“/”的 URL。 http://example.com http://example.com/
我正在开发一个启动器。它让用户从列表中添加小部件,它工作正常。当用户向屏幕添加小部件时,我将有关小部件的信息(PackageName、ClassName 及其在屏幕上的坐标)存储在我的数据库中。
当应用程序重新启动(或设备本身)时,我通过代码添加这些(用户选择的)小部件:
// APPWIDGET_HOST_ID is any number you like
appWidgetManager = AppWidgetManager.getInstance(this);
appWidgetHost = new AppWidgetHost(this, APPWIDGET_HOST_ID);
AppWidgetProviderInfo newAppWidgetProviderInfo = new AppWidgetProviderInfo();
// Get an id
int appWidgetId = appWidgetHost.allocateAppWidgetId();
// Get the list of installed widgets
List<AppWidgetProviderInfo> appWidgetInfos = new ArrayList<AppWidgetProviderInfo>();
appWidgetInfos = appWidgetManager.getInstalledProviders();
for(int j = 0; j < appWidgetInfos.size(); j++)
{
if (appWidgetInfos.get(j).provider.getPackageName().equals(PackageName) && appWidgetInfos.get(j).provider.getClassName().equals(ClassName))
{
// Get the full info of the required widget
newAppWidgetProviderInfo = appWidgetInfos.get(j);
break;
}
}
// Create Widget
AppWidgetHostView hostView …Run Code Online (Sandbox Code Playgroud) 长时间读者,第一次询问,请轻轻一点;)
我有一个Android代码,在ImageView上显示大约10张图片.(在ImageView上调用setImageBitmap来设置新的位图)这会导致显示滞后,所以我试图尽可能地加速它.
我发现(使用traceview)应用程序在方法上花费了大量时间:
ViewRoot.performTraversals
View.measure
FrameLayout.onmeasure
ViewGrou.measureChildWithMargins
Run Code Online (Sandbox Code Playgroud)
我怀疑在ImageView测量,所以我创建了CustomImageView并覆盖onMeasure只是为了调用super方法并编写sysout.
似乎每次调用setImageBitmap onmeasure 3次后.位图总是大小相同,所以没有变化.实际上,当图像源发生变化时,它可能会不时发生变化,但只有这样才能重新测量.
我可以改变什么来消除这种测量对应用速度的影响?
如果您需要更多信息,请告诉我,我会提供.
示例代码
final Bitmap bitmapScaled = Bitmap.createScaledBitmap(bitmap2, width, height, false);
imageView2.setScaleType(ScaleType.CENTER_INSIDE);
if (setSize) {
setSize(imageView2, width, height);
}
imageView2.setImageBitmap(bitmapScaled);
Run Code Online (Sandbox Code Playgroud)
我改变的方法,使其工作更快(可能不安全?!)
boolean layout=true;
int noL=1;
@Override
public void requestLayout() {
if (layout){
super.requestLayout();
if (noL>10){
layout=false;
}else{
noL++;
}
}
}
Run Code Online (Sandbox Code Playgroud)