小编P R*_*ant的帖子

Android:setResult无法正常工作

场景:我有一个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. …

java android android-intent

8
推荐指数
2
解决办法
2万
查看次数

如何设置布局的宽度和高度的动画?

我有一个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)

viewIdLinearLayout我点击的ID .从中调用此函数onClick()

java android android-animation android-layout

6
推荐指数
1
解决办法
1万
查看次数

由java中的所有类扩展的默认类

在Java中默认情况下是否所有类都扩展了默认类?

示例:如果我有一个简单的类,如:

Class A
{
String a;
}
Run Code Online (Sandbox Code Playgroud)

这个类默认是扩展一个类吗?

java inheritance class extend

5
推荐指数
1
解决办法
6681
查看次数

错误:字段名称不能声明为static

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

解决这个问题?

java static multithreading inner-classes

5
推荐指数
2
解决办法
3486
查看次数

Android AsyncTask的onProgressUpdate不起作用

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)

java android android-asynctask progress-bar

3
推荐指数
1
解决办法
6728
查看次数

Android:如何用一根手指旋转视图

我需要旋转一个有一些按钮的视图。随着手指的移动,视图也应该相应地随着它的子视图旋转。

到目前为止,我已经实现了这一点:

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)

animation android image-rotation

3
推荐指数
1
解决办法
3229
查看次数

为什么答案会"好"?

以下是我试图运行的代码,输出是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 interface class object

0
推荐指数
1
解决办法
72
查看次数