0

次のように onCreate と OnResume を含むアプリケーションがあります。

メニューアクティビティ

public class MenuActivity extends Activity   {
    AdView  adView ;
    TextView tv;
    int weekSince;
    int numberOfDaysSince;
    static String DueDateChanged = "com.app.antiwal7amel.DueDateChanged";

    @Override   
     public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);  
        setContentView(R.layout.activitymain);

        tv = (TextView)findViewById(R.id.tv);
      adView = new AdView   (this, AdSize.BANNER , "a15013b6f790555");

         AdRequest adRequest = new AdRequest();
         adRequest.addTestDevice(AdRequest.TEST_EMULATOR);

         RelativeLayout.LayoutParams relativeParams = new RelativeLayout.LayoutParams(
         RelativeLayout.LayoutParams.WRAP_CONTENT, 
         RelativeLayout.LayoutParams.WRAP_CONTENT);
         relativeParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);

         adView.loadAd(adRequest);

//         this.addContentView(adView, relativeParams);
         RelativeLayout rootView = (RelativeLayout)findViewById(R.id.rl);
         rootView.addView(adView, relativeParams);

        ImageButton menu1 = (ImageButton)findViewById(R.id.menu1);
        ImageButton menu2 = (ImageButton)findViewById(R.id.menu2);
        ImageButton menu3 = (ImageButton)findViewById(R.id.menu3);
       ImageButton menu4 = (ImageButton)findViewById(R.id.menu4);
       ImageButton menu5 = (ImageButton)findViewById(R.id.menu5);
       ImageButton menu6 = (ImageButton) findViewById(R.id.menu6);
       ImageButton menu7 = (ImageButton) findViewById(R.id.menu7);
       ImageButton menu9 = (ImageButton)findViewById(R.id.menu9);
       ImageButton menu10 = (ImageButton)findViewById(R.id.menu10);
       ImageButton menu11 = (ImageButton)findViewById(R.id.menu11);

       SharedPreferences periodDatePreferences = PreferenceManager.getDefaultSharedPreferences(this);
         int chosenDay= periodDatePreferences.getInt("chosenDay", 0);
         int chosenMonth =  periodDatePreferences.getInt("chosenMonth", 0);
        int chosenYear =   periodDatePreferences.getInt("chosenYear", 0);
          System.err.println("Shared Preferences main menu "+chosenYear+chosenMonth+chosenDay);


       menu1.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
            Intent i = new Intent(MenuActivity.this,birthDate.class);
            startActivity(i);
                  }

        });


       menu2.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
            Intent i = new Intent(MenuActivity.this,You.class);
            startActivity(i);
                  }

        });

       menu3.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
            Intent i = new Intent(MenuActivity.this,YourBaby.class);
            startActivity(i);
                  }

        });

       menu4.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
            Intent i = new Intent(MenuActivity.this,TataworatYawmeeh.class);
            startActivity(i);
                  }

        });


       menu5.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
            Intent i = new Intent(MenuActivity.this,DoctorVisitsActivity.class);
            startActivity(i);
                  }

        });

       menu6.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
        Intent i = new Intent(MenuActivity.this,QuestionsActivity.class);
        startActivity(i);
              }

    });


       menu7.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
        Intent i = new Intent(MenuActivity.this,AdviceActivity.class);
        startActivity(i);
              }

    });



       menu9.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
            Intent i = new Intent(MenuActivity.this,AboutUsActivity.class);
            startActivity(i);
                  }

        });


      menu10.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            Dialog settingsDialog = new Dialog(MenuActivity.this); 
            settingsDialog.getWindow().requestFeature(Window.FEATURE_NO_TITLE); 
            settingsDialog.setContentView(getLayoutInflater().inflate(R.layout.buttonlayout, null)); 
            settingsDialog.show();

            }
    });

      menu11.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                Intent i = new Intent(MenuActivity.this,Settings.class);
                startActivity(i);
                }
        });
        }

//  @Override
//  protected void onResume() {
//      // TODO Auto-generated method stub
//      
//      SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
//      int birthChosenYear = prefs.getInt("birthChosenYear", MODE_APPEND);
//      int birthChosenMonth = prefs.getInt("birthChosenMonth", MODE_APPEND);
//      int birthChosenDay = prefs.getInt("birthChosenDay", MODE_APPEND);
//      System.err.println("Shared preferences data " + birthChosenDay + "/"
//              + birthChosenMonth + "/" + birthChosenYear);
//      
//      Calendar birthDate = Calendar.getInstance();
//      birthDate.set(birthChosenYear, birthChosenMonth - 1, birthChosenDay);
//      Calendar todayDate = Calendar.getInstance();
//
//      Date todayDated = todayDate.getTime();
//      Date birthDated = birthDate.getTime();
//      SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");
//
//      long dd = birthDated.getTime() - todayDated.getTime();
//      long weeksTillBirth = dd / (1000 * 60 * 60 * 24 * 7);
//
//      System.err.println("todayDateeeeeeee = "
//              + dateFormat.format(todayDated.getTime()));
//      System.err.println("birthDateeeeeee = "
//              + dateFormat.format(birthDated.getTime()));
//      weekSince = (int) (40 - weeksTillBirth);
//      System.err.println("WeeksTillBirth = " + weeksTillBirth);
//      System.err.println("weekSince  = " + weekSince);
//      numberOfDaysSince = weekSince * 7;
//      System.err.println("You are in day  " + numberOfDaysSince);
//
//      
//      System.err.println("onResume");
//      Intent intent = getIntent();
//      String message = intent.getStringExtra("DueDateChanged");
//      System.err.println("message"+message);
//      tv.setText("               You are in day "+numberOfDaysSince + " From your "+weekSince+" Week");
//      super.onResume();
//
//
//  }

onResume からコメント記号を削除すると、XML のアイコンが大きくなり、レイアウト内のすべてが乱雑になります。しかし、onResume内のすべてにコメントすると、すべてがレイアウトとしてうまくいきます!!

なぜ彼が起こったのだろうか!

activitymain.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:id="@+id/rl"

    android:orientation="vertical" android:background="@drawable/mainbackgroundiphone">

 <TableLayout
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"
     android:layout_alignParentTop="true"
     android:background="@drawable/mainbackgroundipad"
     android:orientation="vertical" >

      <TableRow
      android:layout_width="fill_parent"
           android:layout_height="fill_parent" 
           android:layout_marginTop="50dp"> 
      <TextView android:id="@+id/tv"
          android:layout_width="fill_parent"
           android:layout_height="fill_parent"
           android:textColor="#FFFFFF"/>

      </TableRow>

        <TableRow android:id="@+id/tableRow1" 
            android:layout_marginTop="10dp">

            <ImageButton
                android:id="@+id/menu1"
                android:layout_width="75dip"
                android:layout_height="74dip"
                android:layout_marginTop="0dp"
                android:background="@android:color/transparent"
                android:scaleType="fitXY"
                android:src="@drawable/menu1" />

            <ImageButton
                android:id="@+id/menu2"
                android:layout_width="75dp"
                android:layout_height="59dp"
                android:layout_marginLeft="5dp"
                android:layout_marginTop="1dp"
                android:background="@android:color/transparent"
                android:scaleType="fitXY"
                android:src="@drawable/menu2" />

            <ImageButton
                android:id="@+id/menu3"
                android:layout_width="75dip"
                android:layout_height="63dip"
                android:layout_marginLeft="1dp"
                android:layout_marginTop="1dp"
                android:background="@android:color/transparent"
                android:scaleType="fitXY"
                android:src="@drawable/menu3" />

            <ImageButton
                android:id="@+id/menu4"
                android:layout_width="60dp"
                android:layout_height="83dp"
                android:layout_marginRight="100dp"
                android:background="@android:color/transparent"
                android:scaleType="fitCenter"
                android:src="@drawable/menu4" />
        </TableRow>

        <TableRow android:id="@+id/tableRow2"
            android:layout_marginTop="0dp" >

            <ImageButton
                android:id="@+id/menu5"
                android:layout_width="50dp"
                android:layout_height="75dp"
                android:layout_marginLeft="12dp"
                android:layout_marginTop="60dp"
                android:background="@android:color/transparent"
                android:scaleType="fitXY"
                android:src="@drawable/menu5" />

            <ImageButton
                android:id="@+id/menu6"
                android:layout_width="60dp"
                android:layout_height="79dp"
                android:layout_marginTop="60dp"
                android:background="@android:color/transparent"
                android:scaleType="fitXY"
                android:src="@drawable/menu6" />

            <ImageButton
                android:id="@+id/menu7"
                android:layout_width="60dip"
                android:layout_height="86dip"
                android:layout_marginLeft="5dp"
                android:layout_marginTop="60dp"
                android:background="@android:color/transparent"
                android:scaleType="fitStart"
                android:src="@drawable/menu7" />

            <ImageButton
                android:id="@+id/menu8"
                android:layout_width="75dip"
                android:layout_height="50dip"
                android:layout_centerVertical="true"
                android:layout_marginRight="110dp"
                android:layout_marginTop="80dp"
                android:background="@android:color/transparent"
                android:scaleType="fitXY"
                android:src="@drawable/menu8" />
        </TableRow>

        <TableRow android:id="@+id/tableRow3" android:layout_marginTop="1dp" 
           >

            <ImageButton
                android:id="@+id/menu9"
                android:layout_width="60px"
                android:layout_height="80px"
                android:layout_marginLeft="2dp"
                android:layout_marginTop="40dp"
                android:background="@android:color/transparent"
                android:scaleType="fitXY"
                android:src="@drawable/menu9" />

            <ImageButton
                android:id="@+id/menu10"
                android:layout_width="75dip"
                android:layout_height="56dip"
                android:layout_alignParentLeft="true"
                android:layout_marginLeft="2dp"
                android:layout_marginTop="40dp"
                android:background="@android:color/transparent"
                android:scaleType="fitXY"
                android:src="@drawable/menu10" />

            <ImageButton
                android:id="@+id/menu11"
                android:layout_width="75dip"
                android:layout_height="65dip"
                android:layout_alignParentLeft="true"
                android:layout_marginLeft="2dp"
                android:layout_marginTop="40dp"
                android:background="@android:color/transparent"
                android:scaleType="fitXY"
                android:src="@drawable/menu11" />

            <ImageButton
                android:id="@+id/menu12"
                android:layout_width="60dp"
                android:layout_height="60dp"
                android:layout_marginRight="100dp"
                android:layout_marginTop="40dp"
                android:background="@android:color/transparent"
                android:scaleType="fitXY"
                android:src="@drawable/menu12" />
        </TableRow>
    </TableLayout>

</RelativeLayout>

onResume がコメントされていない場合は、次のようになります。

ここに画像の説明を入力

4

1 に答える 1

0

私はあなたが最初にスーパーを呼ぶべきだと思います!あなたに与える;

  @Override

protected void onResume(){TODO自動生成されたメソッドスタブsuper.onResume(); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); int birthChosenYear = prefs.getInt( "birthChosenYear"、MODE_APPEND); int birthChosenMonth = prefs.getInt( "birthChosenMonth"、MODE_APPEND); int birthChosenDay = prefs.getInt( "birthChosenDay"、MODE_APPEND); System.err.println("共有設定データ"+ birthChosenDay + "/" + birthChosenMonth + "/" + birthChosenYear);

  Calendar birthDate = Calendar.getInstance();
  birthDate.set(birthChosenYear, birthChosenMonth - 1, birthChosenDay);
  Calendar todayDate = Calendar.getInstance();

  Date todayDated = todayDate.getTime();
  Date birthDated = birthDate.getTime();
  SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");

  long dd = birthDated.getTime() - todayDated.getTime();
  long weeksTillBirth = dd / (1000 * 60 * 60 * 24 * 7);

  System.err.println("todayDateeeeeeee = "
          + dateFormat.format(todayDated.getTime()));
  System.err.println("birthDateeeeeee = "
          + dateFormat.format(birthDated.getTime()));
  weekSince = (int) (40 - weeksTillBirth);
  System.err.println("WeeksTillBirth = " + weeksTillBirth);
  System.err.println("weekSince  = " + weekSince);
  numberOfDaysSince = weekSince * 7;
  System.err.println("You are in day  " + numberOfDaysSince);


  System.err.println("onResume");
  Intent intent = getIntent();
  String message = intent.getStringExtra("DueDateChanged");
  System.err.println("message"+message);
  tv.setText("               You are in day "+numberOfDaysSince + " From your "+weekSince+" Week");

}

于 2013-01-13T14:10:34.623 に答える