我想将一个整数的新值从一个Activity传递给另一个Activity.即:
活动B包含一个
integer[] pics = { R.drawable.1, R.drawable.2, R.drawable.3}
Run Code Online (Sandbox Code Playgroud)
我希望活动A将新值传递给活动B:
integer[] pics = { R.drawable.a, R.drawable.b, R.drawable.c}
Run Code Online (Sandbox Code Playgroud)
以某种方式通过
private void startSwitcher() {
Intent myIntent = new Intent(A.this, B.class);
startActivity(myIntent);
}
Run Code Online (Sandbox Code Playgroud)
我可以设置这个整数值.
我知道这可以通过捆绑包以某种方式完成,但我不确定如何将这些值从活动A传递到活动B.
我试图让onclicklistener调用意图卸载应用程序,让意图从应用程序设置调用默认的"卸载应用程序"活动.我在这里 发现我可以使用ACTION_UNINSTALL_PACKAGE,com.packageXYXY卸载一个应用程序,这似乎是我正在寻找的.但是,我不确定如何称呼它.我尝试过以下方法:
public void onClick(DialogInterface dialog, int which) {
Uri packageURI = Uri.parse("package:com.packageName");
Intent uninstallIntent = new Intent(Intent.ACTION_UNINSTALL_PACKAGE, packageURI);
startActivity(uninstallIntent);
Run Code Online (Sandbox Code Playgroud)
但语法错了.已经尝试了许多不同的方式来调用它,并且有点卡住了.不知道怎么称呼这个.谢谢你的帮助.
我试图使用OnTouchListener捕获双击事件.我想我会为motionEvent.ACTION_DOWN设置一个long,为第二个motionEvent.ACTION_DOWN设置一个不同的long,并测量它们之间的时间,然后用它做一些事情.但是,我很难弄清楚如何处理这个问题.我正在使用switch case来获取多点触控事件,因此我宁愿不尝试重新设计这一切来实现GestureDetector(不幸的是,同时实现ontouchlistener和Gesturedetector是不可能的).任何想法都会有很大帮助:
i.setOnTouchListener(new OnTouchListener() {
public boolean onTouch(View v, MotionEvent event) {
ImageView i = (ImageView) v;
switch (event.getAction() & MotionEvent.ACTION_MASK) {
case MotionEvent.ACTION_DOWN:
long firstTouch = System.currentTimeMillis();
///how to grab the second action_down????
break;
Run Code Online (Sandbox Code Playgroud) 按下后,我很难让后退按钮实际完成我的活动.我正在运行一个非常简单的视频,使用progressdialog来显示加载对话框和onpreparedlistener等等简单的东西.无论如何,目前当我按下后退按钮时,它将取消progressdialog,并留下黑屏,然后再次按下,progressdialog重新启动!然后当我再次单击后退按钮时,它会显示一个警告对话框,"视频无法播放".很烦人.谢谢你的帮助.
public class VideoActivity extends Activity {
private VideoView mVideoView;
private static ProgressDialog progressdialog;
private String path;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.videoview);
progressdialog = ProgressDialog.show(this, "", " Video Loading...", true);
progressdialog.setCancelable(true);
mVideoView = (VideoView) findViewById(R.id.surface_view);
mVideoView.setMediaController(new MediaController(this));
Bundle b = this.getIntent().getExtras();
path = b.getString("path");
mVideoView.setVideoURI(Uri.parse(path));
mVideoView.setOnPreparedListener(new OnPreparedListener() {
public void onPrepared(MediaPlayer mp) {
progressdialog.dismiss();
mVideoView.requestFocus();
mVideoView.start();
}
});
}
@Override
public void onBackPressed() {
// TODO Auto-generated method stub
super.onBackPressed();
super.finish();
}
}
Run Code Online (Sandbox Code Playgroud) 当我尝试使用admob sdk 4.3.1在我的Android应用程序中实现一个admob横幅时,我得到一个非常讨厌的ClassNotFound异常.我使用了以下实现:
表现:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.xxx"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="10"
/>
....
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<activity android:name="com.google.ads.AdActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"/>
Run Code Online (Sandbox Code Playgroud)
main.xml:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
android:id="@+id/bigmainlayout"
android:layout_width="fill_parent"
android:layout_height="fill_parent" android:background="@color/grey">
<com.google.ads.AdView android:id="@+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
ads:adUnitId="xxxx"
ads:adSize="BANNER"
ads:testDevices="TEST_EMULATOR"
ads:loadAdOnCreate="true"/>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
Project.properties
target=android-14
Run Code Online (Sandbox Code Playgroud)
错误:
03-21 22:00:25.993:E/AndroidRuntime(333):FATAL EXCEPTION:main 03-21 22:00:25.993:E/AndroidRuntime(333):java.lang.RuntimeException:无法启动活动ComponentInfo {com. xxxx/com.xxxx.MainActivity}:android.view.InflateException:二进制XML文件行#125:错误膨胀类com.google.ads.AdView 03-21 22:00:25.993:E/AndroidRuntime(333):at android .app.ActivityThread.performLaunchActivity(ActivityThread.java:1647)03-21 22:00:25.993:E/AndroidRuntime(333):at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)03-21 22:00 :25.993:E/AndroidRuntime(333):在android.app.ActivityThread.access $ 1500(ActivityThread.java:117)03-21 22:00:25.993:E/AndroidRuntime(333):在android.app.ActivityThread $ H .handleMessage(ActivityThread.java:931)03-21 22:00:25.993:E/AndroidRuntime(333):at android.os.Handler.dispatchMessage(Handler.java:99)03-21 22:00:25.993:E/AndroidRuntime(333):在android.os.Looper.loop(Looper.java:123)03-21 22:00:25.993:E/AndroidRuntime(333):在android.app.ActivityThread.main(ActivityThread.java:3683)03-21 22:00:25.993:E/AndroidRuntime(333):at java.lang.reflect.Method.invokeNative(Native Method)03-21 22 :00:25.993:E/AndroidRuntime(333):at java.lang.reflect.Method.invoke(Method.java:507)03-21 22:00:25.993:E/AndroidRuntime(333):at com.android. internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:839)03-21 22:00:25.993:E/AndroidRuntime(333):at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597 …
我有一个带有多点触控的imageView,大致基于本教程.其中一位评论者将图像拖动限制在图像边界的半脏方法放在一起,这样图像边缘就不会被拖到边缘之外.这种方法有效,但不完全.它只限制两条边的拖动.
有没有人知道一个不那么混乱和实际功能的方法来限制图像拖动?
这是Android应用程序开发的一个非常重要的概念,没有得到充分解决....
我在考虑以下想法:
1)当zoom = 1.0F(即最小缩放)时setScaleType(scaleType.fitXY),并且只有在zoom> 1.0f时才启用拖动
2)当缩放> 1.0f,setScaleType(scaleType.MATRIX),然后你确定图像边界和屏幕尺寸,并且在某种程度上对我来说太聪明了,使用if语句你只允许在图像边缘没有打开时拖动屏幕.我不知道如何宣布,是的.
无论如何,为了完整性,这里是该链接的限制泛码.这似乎是stackoverflow上最受欢迎的建议,但我认为我们可以做得更好:
// limit pan
matrix.getValues(matrixValues);
float currentY = matrixValues[Matrix.MTRANS_Y];
float currentX = matrixValues[Matrix.MTRANS_X];
float currentScale = matrixValues[Matrix.MSCALE_X];
float currentHeight = height * currentScale;
float currentWidth = width * currentScale;
float dx = event.getX() - start.x;
float dy = event.getY() - start.y;
float newX = currentX+dx;
float newY = currentY+dy;
RectF drawingRect = new RectF(newX, newY, newX+currentWidth, newY+currentHeight);
float diffUp = Math.min(viewRect.bottom-drawingRect.bottom, viewRect.top-drawingRect.top);
float diffDown = Math.max(viewRect.bottom-drawingRect.bottom, viewRect.top-drawingRect.top);
float …Run Code Online (Sandbox Code Playgroud) 我是Objective-C编码的新手,但我来自移动开发的Java世界.在Android中,我们使用字符串资源,然后指向Java类中的那些资源.我们应该使用iOS中的类似过程,还是将字符串"硬编码"到实现文件中?我还没有找到一个使用localizable字符串(和.strings)文件的好教程.
我在以下查询中得到"索引1处的绑定值为空":
public String searchForWifiSSID(String one, String two){
c = db.query(Constants.TABLE_NAME, new String[]{Constants.PARAM1, Constants.PARAM2}, Constants.PARAM1 + " =? " +" AND " + Constants.PARAM2 + " =? ", new String[]{one,two}, null, null, null);
}
Run Code Online (Sandbox Code Playgroud)
我的selectionArgs语法不正确吗?这样做是不正确的:
public String searchForWifiSSID(String one, String two){
c = db.query(Constants.TABLE_NAME, new String[]{Constants.PARAM1, Constants.PARAM2}, Constants.PARAM1 + " = " + one +" AND " + Constants.PARAM2 + " = " + two, null, null, null, null);
}
Run Code Online (Sandbox Code Playgroud)