可能重复:
如何计算java中的时差?
实际上我想在Java中减去两个日期.我尝试了很多但不能成功.所以任何人都请帮助我.
Date dtStartDate=pCycMan.getStartDate();
Date dtEndDate=pCycMan.getEndDate();
Run Code Online (Sandbox Code Playgroud)
我怎样才能减去这两个日期?
从 android 市场,我得到了以下崩溃报告。我在测试我的应用程序时没有发现这一点。事故发生在PasswordActivity
课堂上。我正在发送堆栈跟踪和代码。谁能告诉我崩溃发生在哪里以及为什么会发生?
堆栈跟踪
java.lang.IncompatibleClassChangeError: interface not implemented
at in.plackal.lovecyclesfree.PasswordActivity.onCreate(PasswordActivity.java)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
at android.app.ActivityThread.access$2300(ActivityThread.java:125)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:123)
at android.app.ActivityThread.main(ActivityThread.java:4627)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:521)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:878)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:636)
at dalvik.system.NativeStart.main(Native Method)
Run Code Online (Sandbox Code Playgroud)
我的代码
public class PasswordActivity extends Activity Implements Utilities { //私有变量 private EditText m_passwrdEditText;
private TextView m_passwrdErrorText;
private Resources m_res;
@Override
public void onCreate(Bundle savedInstanceState) {
//Setup the activity
super.onCreate(savedInstanceState);
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
DisplayMetrics dm = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(dm);
if (dm.widthPixels == …
Run Code Online (Sandbox Code Playgroud) 实际上我已经使用AlertDialog.builder创建了一个自定义对话框.在这个对话框中我没有显示titile.All工作正常,但对话框中出现黑色边框.所以任何人都可以告诉我如何删除这个黑色的boder.代码和截图如下.
java中的代码:
AlertDialog.Builder start_dialog = new AlertDialog.Builder(this);
Context mContext = getApplicationContext();
LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(LAYOUT_INFLATER_SERVICE);
View layout = inflater.inflate(R.layout.custom_dialog2,
(ViewGroup) findViewById(R.id.layout_root));
layout.setBackgroundResource(R.drawable.img_layover_welcome_bg);
Button btnPositiveError = (Button)layout.findViewById(R.id.btn_error_positive);
btnPositiveError.setTypeface(m_facedesc);
start_dialog.setView(layout);
final AlertDialog alert = start_dialog.create();
alert.show();
btnPositiveError.setOnClickListener(new Button.OnClickListener()
{
public void onClick(View v)
{
alert.dismiss();
}
});
Run Code Online (Sandbox Code Playgroud)
ScrrenShot
我创建了一系列按钮.现在我想找到按钮的高度和宽度,为此我使用了getWidth()和getHeight().但问题是它总是返回0.为什么会发生这种情况?我发送了我的代码,请检查是否有任何问题.
int x,y;
LinearLayout layoutVertical = (LinearLayout) findViewById(R.id.liVLayout);
LinearLayout rowLayout = null;
LayoutParams param = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT, 1);
//Create Button
for (int i = 0; i<6; i++)
{
rowLayout = new LinearLayout(this);
rowLayout.setWeightSum(7);
layoutVertical.addView(rowLayout, param);
for(int j=0; j<7; j++)
{
m_pBtnDay[i][j] = new Button(this);
rowLayout.addView(m_pBtnDay[i][j], param);
m_pBtnDay[i][j].setOnLongClickListener(this);
m_pBtnDay[i][j].setGravity(Gravity.CENTER_HORIZONTAL | Gravity.CENTER_VERTICAL);
m_pBtnDay[i][j].setTextSize(12);
}
}
x = m_pBtnDay[i][j].getWidth();
y = m_pBtnDay[i][j].getHeight();
Log.d("width", Integer.toString(x));
Log.d("Height", Integer.toString(y));
return true;
Run Code Online (Sandbox Code Playgroud) 实际上我在屏幕底部的应用程序中显示一个google.ads.AdView ..一切正常.但唯一的问题是它在三星星系音符中显示时并不占据屏幕的整个宽度,但是在nexus中显示它需要屏幕的整个宽度.
为什么会发生这种情况,是否有办法解决这个问题.
我把我的google.ads.AdView放在我的xml布局中
<LinearLayout
android:id="@+id/bottom_control_bar"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:orientation="horizontal" >
<com.google.ads.AdView
android:id="@+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
ads:adSize="BANNER"
ads:adUnitId="a14e5222d46c63d"
ads:loadAdOnCreate="true" >
</com.google.ads.AdView>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud) 在我的应用程序中,我使用IntentService
类在后台启动另一个活动.但我得到的问题是,从IntentService
课程开始,我开始我的活动,打开我的活动,之后我不关闭我的活动.然后我注意到,当IntentService
类再次想要开始我的同一活动时,它不被调用,因为相同的活动不是关闭的.所以我的问题是我怎样才能一次又一次地开始相同的活动,无论是开课还是近IntentService
课.
IntentService类中的代码
public class AlarmService extends IntentService
{
public void onCreate() {
super.onCreate();
}
public AlarmService() {
super("MyAlarmService");
}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
super.onStartCommand(intent, startId, startId);
return START_STICKY;
}
@Override
protected void onHandleIntent(Intent intent) {
startActivity(new Intent(this,
AlarmDialogActivity.class).setFlags(Intent.FLAG_ACTIVITY_NEW_TASK));
}
}
Run Code Online (Sandbox Code Playgroud) 假设有A,B,C,D和E等活动.我正在活动E中创建一个主页按钮.现在如果我从活动A移动到B,然后移动到C,最后移动到D.
现在,当我点击主页按钮时,当我在D活动中时,我想完成所有其他活动.
因此,当用户再次启动应用程序时,它将不会打开D活动.相反,它将从第一个活动开始,即A.那么如何做到这一点.请建议我.
关心安舒曼
我将DirectoryPath作为"data/data/in.com.jotSmart/app_custom/folderName/FileName"存储为String ArrayList
喜欢
ArrayList<String> a;
a.add("data/data/in.com.jotSmart/app_custom/page01/Note01.png");
Run Code Online (Sandbox Code Playgroud)
现在从这条路径我想得到page01作为单独的字符串和Note01作为单独的字符串并将其存储到两个字符串变量中.我尝试了很多,但无法得到结果.如果有人知道帮助我解决这个问题.
我正在使用一个Canvas
类在画布上绘制线条.现在我想用与使用橡皮擦的笔记本中类似的方式擦除画布中绘制的线条.我通过几个例子,但没有什么对我有用.
如果有人知道这个问题的解决方案,请你帮我解决这个问题.
Java代码
public class DrawView extends View implements OnTouchListener
{
private Canvas m_Canvas;
private Path m_Path;
private Paint m_Paint;
ArrayList<Pair<Path, Paint>> paths = new ArrayList<Pair<Path, Paint>>();
ArrayList<Pair<Path, Paint>> undonePaths = new ArrayList<Pair<Path, Paint>>();
private float mX, mY;
private static final float TOUCH_TOLERANCE = 4;
private Bitmap bitmapToCanvas;
private CanvasManager m_CanvasManagerObject;
private Paint mBitmapPaint;
public DrawView(Context context)
{
super(context);
setFocusable(true);
setFocusableInTouchMode(true);
this.setOnTouchListener(this);
onCanvasInitialization();
}
public void onCanvasInitialization()
{
m_Paint = new Paint(Paint.DITHER_FLAG);
m_Paint.setAntiAlias(true);
m_Paint.setDither(true);
m_Paint.setColor(Color.parseColor("#37A1D1"));
m_Paint.setStyle(Paint.Style.STROKE);
m_Paint.setStrokeJoin(Paint.Join.ROUND);
m_Paint.setStrokeCap(Paint.Cap.ROUND); …
Run Code Online (Sandbox Code Playgroud) 我正在使用Canvas
创建绘图应用程序的 android 类。这是我第一次尝试使用 Canvas 类。到目前为止,我使用的代码工作正常,绘图工作正常。但我在这段代码中意识到,它允许用户仅用一根手指进行绘画,我的意思是说,如果用户使用多于一根手指在画布上绘画,则不允许用户用多根手指进行绘画。我浏览了有关多个触摸事件的文档,但未能在我的代码中实现它。那么有人可以帮我解决这个问题吗?
我用于在画布上绘图的代码:
public class DrawView extends View implements OnTouchListener
{
private Canvas m_Canvas;
private Path m_Path;
private Paint m_Paint;
ArrayList<Pair<Path, Paint>> arrayListPaths = new ArrayList<Pair<Path, Paint>>();
ArrayList<Pair<Path, Paint>> undonePaths = new ArrayList<Pair<Path, Paint>>();
private float mX, mY;
private Bitmap bitmapToCanvas;
private static final float TOUCH_TOLERANCE = 4;
public DrawView(Context context)
{
super(context);
setFocusable(true);
setFocusableInTouchMode(true);
this.setOnTouchListener(this);
onCanvasInitialization();
}
public void onCanvasInitialization()
{
m_Paint = new Paint();
m_Paint.setAntiAlias(true);
m_Paint.setDither(true);
m_Paint.setColor(Color.parseColor("#37A1D1"));
m_Paint.setStyle(Paint.Style.STROKE);
m_Paint.setStrokeJoin(Paint.Join.ROUND);
m_Paint.setStrokeCap(Paint.Cap.ROUND);
m_Paint.setStrokeWidth(2);
m_Path = …
Run Code Online (Sandbox Code Playgroud)