Switch case in Android-app

Hier ist der code, soll ein Dialogfeld zu öffnen, wenn ich drücken Sie die Schaltfläche info in meiner min-Aktivität Seite. Aber nichts wirklich passiert. : /

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

        View continueButton = findViewById(R.id.continue_button);
        continueButton.setOnClickListener(this);

        View newgameButton = findViewById(R.id.new_button);
        continueButton.setOnClickListener(this);

        View aboutButton = findViewById(R.id.about_button);
        continueButton.setOnClickListener(this);

        View exitButton = findViewById(R.id.exit_button);
        continueButton.setOnClickListener(this);




public void onClick(View v) {

        switch (v.getId()) {
        case R.id.continue_button:
                break;
        case R.id.about_button:     
                Intent i = new Intent(this, About.class);
                startActivity(i);
                break;
        case R.id.new_button: 
                openNewGameDialog(); 
                break;
        case R.id.exit_button:
                finish();
                break;  


        }       
    }

Haupttätigkeit XML

<LinearLayout
   xmlns:android="http://schemas.android.com/apk/res/android"
   android:background="@color/background"
   android:layout_height="fill_parent"
   android:layout_width="fill_parent"
   android:padding="30dip"
   android:orientation="horizontal" >
<LinearLayout
   android:orientation="vertical"
   android:layout_height="wrap_content"
   android:layout_width="fill_parent"
   android:layout_gravity="center" >
 <TextView
   android:text="@string/main_title"
   android:layout_height="wrap_content"
   android:layout_width="wrap_content"
   android:layout_gravity="center"
   android:layout_marginBottom="25dip"
   android:textSize="24.5sp" />
 <Button
   android:id="@+id/continue_button"
   android:layout_width="fill_parent"
   android:layout_height="wrap_content"
   android:text="@string/continue_label" />
 <Button
   android:id="@+id/new_button"
   android:layout_width="fill_parent"
   android:layout_height="wrap_content"
   android:text="@string/new_game_label" />
 <Button
   android:id="@+id/about_button"
   android:layout_width="fill_parent"
   android:layout_height="wrap_content"
   android:text="@string/about_label" />
 <Button
   android:id="@+id/exit_button"
   android:layout_width="fill_parent"
   android:layout_height="wrap_content"
   android:text="@string/exit_label" />
</LinearLayout>
</LinearLayout>

Beispiel für eine Schaltfläche: Über

Über Die Tätigkeit

public class About extends Activity {

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

    }

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

}

Über XML -

<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="10dip" >
<TextView
android:id="@+id/about_content"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/about_text" />
</ScrollView>
post gesamte Tätigkeit code
bitte fügen Sie bestimmten code Ihrer Tätigkeit . so dass ich Ihnen helfen kann
ok, hier ist der code.
void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R. layout.main); Ansicht continueButton = findViewById(R. id.continue_button); continueButton.setOnClickListener(this); View newgameButton = findViewById(R. id.new_button); continueButton.setOnClickListener(this); View aboutButton = findViewById(R. id.about_button); continueButton.setOnClickListener(this); exitButton = findViewById(R. id.exit_button); continueButton.setOnClickListener(this); }
Sorry für das Durcheinander . Ich bin ziemlich neu in diesem

InformationsquelleAutor SagiAharon | 2013-11-13

Schreibe einen Kommentar