场景:我有一个MainActivity.java,OtherPageForFragments.java和片段,其中上OtherPageForFragments.java
在MainActivity.java,我编写了以下代码来启动一个活动并获得结果
onActivityResult(int requestCode,int resultCode,Intent data)
是
startActivityForResult(new Intent(this, OtherPageForFragments.class),REQUEST_CODE_MAP);
Run Code Online (Sandbox Code Playgroud)
在onDestroy()片段类中,我写了这个:
public void onDestroyView() {
// TODO Auto-generated method stub
super.onDestroyView();
mlocManager.removeUpdates(this);
Intent intent = new Intent();
intent.putExtra("Latitude", passLatLng.latitude);
intent.putExtra("Longitude", passLatLng.longitude);
getActivity().setResult(Activity.RESULT_OK, intent);
getActivity().finish();
}
Run Code Online (Sandbox Code Playgroud)
现在,我希望我的成绩在MainActivity课堂上.所以,我在onActivityResult方法中编写了以下代码:
if (resultCode == Activity.RESULT_OK && requestCode == REQUEST_CODE_MAP)
{
tost("2");
double lat=data.getExtras().getDouble("Latitude");
double lng=data.getExtras().getDouble("Longitude");
tost(lat + " -- " + lng);
}
Run Code Online (Sandbox Code Playgroud)
问题:resultCode返回的不是Activity.RESULT_OK,Intent我得到的是null. …
我有一个LinearLayout通过隐藏所有其他布局和视图扩展到全屏幕onClick.有一个Relativelayout上面LinearLayout
我想对此应用自定义动画.尺寸应该缓慢增加(如在500毫秒内).
但我怀疑是否可能?谢谢.
这是我在做的事情onClick:
private void expandView (int viewId) {
RelativeLayout relativeLayout = (RelativeLayout) ((LinearLayout) view.findViewById(viewId)).getParent();
ViewGroup.MarginLayoutParams rlMargin = (ViewGroup.MarginLayoutParams) relativeLayout.getLayoutParams();
rlMargin.setMargins(0, 0, 0, 0);
relativeLayout.setLayoutParams(rlMargin);
LinearLayout linearLayout = (LinearLayout) relativeLayout.getParent();
hideAllLinearLayoutExcept(linearLayout.getId());
hideAllTilesExcept(viewId);
}
Run Code Online (Sandbox Code Playgroud)
viewId是LinearLayout我点击的ID .从中调用此函数onClick()
在Java中默认情况下是否所有类都扩展了默认类?
示例:如果我有一个简单的类,如:
Class A
{
String a;
}
Run Code Online (Sandbox Code Playgroud)
这个类默认是扩展一个类吗?
public class Application {
public static void main(String[] args) {
final class Constants {
public static String name = "globe";
}
Thread thread = new Thread(new Runnable() {
@Override
public void run() {
System.out.println(Constants.name);
}
});
thread.start();
}
}
Run Code Online (Sandbox Code Playgroud)
编译错误: The field name cannot be declared static in a non-static inner type, unless initialized with a constant expression
解决这个问题?
我AsyncTask上课了.我希望它在执行过程中显示进度.但它不是打印日志.
private void registerBackground() {
new AsyncTask<Void, Integer, String>() {
@Override
protected String doInBackground(Void... params) {
Log.v("TAGGG", "IN doInBackground");
msg = "Error: ";
return msg;
}
@Override
protected void onProgressUpdate(Integer... progress) {
super.onProgressUpdate(progress);
Log.v("TAGGG", "Progress: " + progress[0] + "%");
}
@Override
protected void onPostExecute(String msg)
{
Log.v("TAGGG", msg);
}
}.execute();
}
Run Code Online (Sandbox Code Playgroud) 我需要旋转一个有一些按钮的视图。随着手指的移动,视图也应该相应地随着它的子视图旋转。
到目前为止,我已经实现了这一点:
private RelativeLayout mCircle;
private double mCurrAngle = 0;
private double mPrevAngle = 0;
int i = 0;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mCircle = (RelativeLayout) findViewById(R.id.circle);
mCircle.setOnTouchListener(this); // Your activity should implement
// OnTouchListener
}
@Override
public boolean onTouch(View v, MotionEvent event) {
final float xc = mCircle.getWidth() / 2;
final float yc = mCircle.getHeight() / 2;
final float x = event.getX();
final float y = event.getY();
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN: {
mCircle.clearAnimation();
mCurrAngle …Run Code Online (Sandbox Code Playgroud) 以下是我试图运行的代码,输出是Good.那么,我们可以使用一个类实现的接口变量吗?
interface IDummyInterface {
public String TYPE = "Good";
}
class Test implements IDummyInterface {
}
public class MyApplication {
public static void main(String[] args) {
System.out.println(Test.TYPE);
}
}
Run Code Online (Sandbox Code Playgroud) java ×6
android ×4
class ×2
animation ×1
extend ×1
inheritance ×1
interface ×1
object ×1
progress-bar ×1
static ×1