2016-10-22 8 views
-1

アプリを終了する別のコードがありますか? なぜ私はここで働いていないのか分かりません。 おそらくその約xmlファイルについて私はその重いまたは私のコードを修正する必要があると思う。なぜ私は終了したいときに強制的に閉じるのですか?

はここ

package ir.whitegate.guardians; 

import android.app.Activity; 
import android.content.Context; 
import android.content.Intent; 
import android.os.Bundle; 
import android.widget.Button; 
import android.view.View; 
import android.view.View.OnClickListener; 

public class MainActivity extends Activity { 

Button button; 

@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.main); 
    addListenerOnButton(); 
    getActionBar().hide(); 

} 

public void addListenerOnButton() { 

    final Context context = this; 

    button = (Button) findViewById(R.id.buttonstory); 

    button.setOnClickListener(new OnClickListener() { 

      @Override 
      public void onClick(View arg0) { 

       Intent intent = new Intent(context, Story.class); 
       startActivity(intent); 

      } 
      public void EXIT(View view) 
      { 
       finish(); 
      } 
     }); 

} 
} 

、ここでは私のxml

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout 
xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_height="match_parent" 
android:layout_width="match_parent" 
android:orientation="vertical" 
android:background="@drawable/mainsithis"> 

<RelativeLayout 
    android:layout_height="82dp" 
    android:layout_width="match_parent"> 

    <HorizontalScrollView 
     android:layout_height="wrap_content" 
     android:layout_width="wrap_content"> 

     <LinearLayout 
      android:layout_height="wrap_content" 
      android:layout_width="82dp" 
      android:orientation="horizontal"> 

      <Button 
       android:layout_height="82dp" 
       android:layout_width="35dp" 
       android:background="@drawable/toleft"/> 

      <Button 
       android:layout_height="match_parent" 
       android:layout_width="82dp" 
       android:background="@drawable/bios"/> 

      <Button 
       android:layout_height="match_parent" 
       android:layout_width="82dp" 
       android:background="@drawable/howtoread"/> 

      <Button 
       android:layout_height="match_parent" 
       android:layout_width="82dp" 
       android:background="@drawable/about"/> 

      <Button 
       android:layout_height="match_parent" 
       android:layout_width="82dp" 
       android:background="@drawable/writer"/> 

      <Button 
       android:layout_height="match_parent" 
       android:layout_width="82dp" 
       android:background="@drawable/rateit"/> 

      <Button 
       android:layout_height="match_parent" 
       android:layout_width="82dp" 
       android:background="@drawable/moreapps"/> 

      <Button 
       android:layout_height="82dp" 
       android:layout_width="35dp" 
       android:background="@drawable/toright"/> 

     </LinearLayout> 

    </HorizontalScrollView> 

</RelativeLayout> 

<LinearLayout 
    android:layout_height="match_parent" 
    android:layout_width="match_parent" 
    android:orientation="horizontal" 
    android:layout_weight="0.25" 
    android:background="@drawable/rainbow"/> 

<LinearLayout 
    android:layout_height="match_parent" 
    android:layout_width="match_parent" 
    android:orientation="horizontal" 
    android:layout_weight="0.80"> 

    <Button 
     android:id="@+id/buttonstory" 
     android:layout_height="65dp" 
     android:layout_width="wrap_content" 
     android:background="@drawable/starttoread" 
     android:layout_weight="1.0"/> 

    <Button 
     android:layout_height="65dp" 
     android:layout_width="wrap_content" 
     android:background="@drawable/exit" 
     android:layout_weight="1.0" 
     android:onClick="EXIT"/> 

</LinearLayout> 

+1

エラースタックトレース – Sanjeet

+0

コードで表示できますか? –

+0

ログカットに入っているエラーログです – Sanjeet

答えて

0

あなたはボタンclicklistenerからクラスにEXITメソッドを移動する必要がある私のコードです。

方法

0
public void addListenerOnButton() { 

final Context context = this; 

button = (Button) findViewById(R.id.buttonstory); 

button.setOnClickListener(new OnClickListener() { 

     @Override 
     public void onClick(View arg0) { 

      Intent intent = new Intent(context, Story.class); 
      startActivity(intent); 

     } 

    }); 

} 

public void EXIT(View view) 
     { 
      finish(); 
     } 

変化

Intent intent = new Intent(context, Story.class); 

意図意図=新しいテント(MainActivity.this、Story.class)以下のような変更addListenerOnButton方法を、

間違ったパラメータコンテキストbuttonStory android:onClick="EXIT"

移動これはMainActivityにコードを追加します。

public void EXIT(View view) 
     { 
      finish(); 
     } 
関連する問題