Android Studio imageButton und dem Wechsel zu einer anderen Aktivität

UPDATE:

Ich habe 4 imageButtons und jeder braucht einen "setOnClickListener" oder ähnlich. Sobald der listener feuert, ich habe die Absicht, den Benutzer zu der nächsten Aktivität, die derzeit nur eine leere Seite:

public void onClick(View v){
Intent intent = new Intent(MainActivity.this, NewSong.class);
startActivity(intent);
}

Angefangen habe ich mit 4 Tasten, und es hatte alles funktioniert, und dann beschlossen, imageButtons, anstatt für ästhetik.

Ich bin mir nicht sicher, was der Unterschied ist in "Tasten" und "imageButtons" sind, aber Sie sicherlich können nicht vertauschen. Meine besten "Googeln" hat sich nicht jede Lösung so weit in das Verständnis, wie Sie ändern, meine früheren "button" - Lösung.

Jedem helfen würde willkommen sein,

Ed

Hier ist die MainActivity.java code:

public class MainActivity extends ActionBarActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        //In this next line, note that 'btn' will never be used, it's
        //grayed out in the "Button btn...", and in the (R.id.btn) it is 
        //shown in red font, indicating I probably need to declare a resource of some kind?
        Button btn = (Button)findViewById(R.id.btn);


        Button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(MainActivity.this,    NewSong.class);
                startActivity(intent);
            }
        });
    }


    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        //Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.menu_main, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        //Handle action bar item clicks here. The action bar will
        //automatically handle clicks on the Home/Up button, so long
        //as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();

        //noinspection SimplifiableIfStatement
        if (id == R.id.action_settings) {
            return true;
        }

        return super.onOptionsItemSelected(item);
    }
}

Und hier ist die activity_main.xml:

<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:paddingBottom="@dimen/activity_vertical_margin"
    tools:context=".MainActivity"
    android:clickable="true">



    <ImageButton
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/imageButton"
        android:background="@drawable/new_song"
        android:layout_centerVertical="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"/>

    <ImageButton
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/imageButton2"
        android:background="@drawable/loadsong"
        android:layout_alignTop="@+id/imageButton"
        android:layout_toRightOf="@+id/imageButton"
        android:layout_toEndOf="@+id/imageButton"
        android:layout_marginLeft="55dp"
        android:layout_marginStart="55dp"/>


</RelativeLayout>
Was ist das problem, dass Sie konfrontiert sind?
Können Sie bitte erklären Sie Ihr problem im detail?
Mein problem ist, dass ich nicht finden können, die 'Magie' code, erlaubt mir, auf ein imageButton-Steuerelement, statt einer Taste. Ich habe gerade meinen Beitrag aktualisiert mit neuen Informationen, code und einige Kommentare. Vielen Dank für alle unterstützen.

InformationsquelleAutor user1359407 | 2015-02-23

Schreibe einen Kommentar