Ich habe ein Problem mit meinem Code, wenn ich den Knopf drücke Ich möchte die Bildansicht zu 1 der Bilder ändern das Problem ist, dass er nur 1 Bild ändern und aufhören zu arbeiten, ich versuche für und es nicht .
Und zweite Problem, wenn ich zweite Taste die App abgestürzt gedrückt, und hier ist das Protokoll:ImageView Änderung bei Klickfehler
E/AndroidRuntime: FATAL EXCEPTION: main
java.lang.ArrayIndexOutOfBoundsException: length=12; index=-1
at com.example.hanansanag.mytourneyccreator.Players.onClick(Players.java:47)
at android.view.View.performClick(View.java:4240)
at android.view.View$PerformClick.run(View.java:17721)
at android.os.Handler.handleCallback(Handler.java:730)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5103)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
at dalvik.system.NativeStart.main(Native Method)
der Code der Andrang:
else if (btnBeck==v) {
iv.setBackgroundResource(pic[--i]);
}
und das Problem Code Klasse nächstes Bild Taste :
package com.example.hanansanag.mytourneyccreator;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.ImageSwitcher;
import android.widget.ImageView;
/**
* Created by ssh on 25/12/2016.
*/
public class Players extends AppCompatActivity implements View.OnClickListener {
protected Button btnNext, btnBeck;
protected ImageView iv;
protected String fname;
protected String Lname;
protected String team;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.team_pic);
btnNext = (Button) findViewById(R.id.btnNextPic);
btnBeck = (Button) findViewById(R.id.btnBeckPic);
iv = (ImageView) findViewById(R.id.imageView);
btnNext.setOnClickListener(this);
btnBeck.setOnClickListener(this);
}
@Override
public void onClick(View v) {
int i=0;
int[] pic = {R.drawable.barcelona, R.drawable.athletico, R.drawable.arsenal1, R.drawable.chelsea,
R.drawable.dortmond, R.drawable.bayrenminchen, R.drawable.inter, R.drawable.realmadrid,
R.drawable.macabiheifa, R.drawable.macabitelaviv, R.drawable.beitar, R.drawable.bersheva};
if (btnNext==v) {
iv.setBackgroundResource(pic[++i]);
}
else if (btnBeck==v) {
iv.setBackgroundResource(pic[--i]);
}
}
}
XML-Datei:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/teampic"
android:orientation="horizontal" android:layout_width="wrap_content"
android:layout_height="wrap_content">
<GridLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/gridLayout"/>
<TextView
android:text="Fname"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_toEndOf="@+id/imageView"
android:layout_marginTop="12dp"
android:id="@+id/textView2" />
<TextView
android:text="Lname"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:id="@+id/Lname"
android:layout_below="@+id/textView2"
android:layout_toEndOf="@+id/imageView" />
<TextView
android:text="Fname"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_toEndOf="@+id/imageView"
android:layout_marginTop="12dp"
android:id="@+id/textView3" />
<GridLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/textView2"
android:layout_toEndOf="@+id/textView2">
<Button
android:layout_width="20dp"
android:layout_height="15dp"
android:id="@+id/btnBeckPic"
android:background="@drawable/btnbeck"
android:layout_marginStart="30dp"
android:layout_alignBottom="@+id/Lname"
android:layout_toEndOf="@+id/textView2" />
<Button
android:background="@drawable/btnnext"
android:layout_width="20dp"
android:layout_height="15dp"
android:id="@+id/btnNextPic"
android:layout_below="@+id/imageView"
android:layout_toEndOf="@+id/btnBeckPic"
android:layout_marginStart="14dp" />
</GridLayout>
<ImageView
android:layout_height="50dp"
android:id="@+id/imageView"
android:layout_width="60dp"
android:layout_below="@+id/gridLayout"
android:layout_toEndOf="@+id/gridLayout"/>
</RelativeLayout>
manefist wenn Bedarf:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.hanansanag.mytourneyccreator">
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".OpeningScreen">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<activity android:name=".Players"></activity>
<activity android:name=".MainScreen"></activity>
</application>
</manifest>
hallo bro ty so viel seiner Arbeit, aber ich habe Probleme afther er zum las pic gehen und zu tun: –
hallo bro ty so viel seiner Arbeit, aber ich habe Probleme afther er zum las pic gehen und Mach die Rückkehr er stoppt, um Bild zu bewegen, wie ich das tue er wird nicht aufhören und der Benutzer wird weiter gehen und ändern, wie viel er will ..? und tue so viel für deine Zeit –