###前提・実現したいこと
onCreateの中にあるコードが実行されません。
onClickなども同様です
ページは横スワイプ画面のページの中の一つです
実行自体はできてレイアウトファイルの定義通りに表示はされましたが処理が行われません
どうすれば良いのでしょうか
コードは「このページ」のものです
具体的に教えていただけるとありがたいです
よろしくお願いします
###発生している問題・エラーメッセージ
特にありませんが指定した処理が実行されません
###該当のソースコード
page1.java(処理が通らない部分のコード >印部分)
java
1 2 3import android.content.Intent; 4import android.content.SharedPreferences; 5import android.os.Bundle; 6import android.support.v7.app.AppCompatActivity; 7import android.util.Log; 8import android.view.View; 9import android.widget.ImageButton; 10import android.widget.TextView; 11 12public class page1 extends AppCompatActivity implements View.OnClickListener { 13private ImageButton imageButton; 14 15 protected void onCreate(Bundle savedInstanceState) { 16 super.onCreate(savedInstanceState); 17 setContentView(R.layout.activity_page1); 18 >Log.d("debug","W"); ・・・・・* 19 >imageButton=(ImageButton)findViewById(R.id.imageButton4); 20 >imageButton.setOnClickListener(this); 21 22 23 >final String PREFERRENCES_FILE_NAME = "PrefrencesFile"; 24 >//プリファレンスのインスタンスを取得 25 >SharedPreferences pre = this.getSharedPreferences(PREFERRENCES_FILE_NAME, MODE_PRIVATE); 26 >//デフォルトプリファレンスのインスタンスを取得する 27 >//SharedPreferences pre = >PreferenceManager.getDefaultSharedPreferences(this); 28 >//読み込み 29 >String str = pre.getString("NAME", "NONE"); 30 >TextView text = (TextView) this.findViewById(R.id.name); 31 >text.setText(str); 32 33 } 34 public void onClick(View v) { 35 >Log.d("debug","g"); ・・・・・* 36 >if (v == imageButton) { 37 > Intent intent = new Intent(this, Setting.class); 38 > startActivityForResult(intent, 0); 39 } 40 } 41 42} 43
activity_page1.xml(page1.javaのレイアウトファイル)
xml
1<?xml version="1.0" encoding="utf-8"?> 2<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 3xmlns:tools="http://schemas.android.com/tools" 4android:layout_width="match_parent" 5android:layout_height="match_parent" 6android:paddingBottom="@dimen/activity_vertical_margin" 7android:paddingLeft="@dimen/activity_horizontal_margin" 8android:paddingRight="@dimen/activity_horizontal_margin" 9android:paddingTop="@dimen/activity_vertical_margin" 10tools:context="com.example.syoribuuser.firstopenandfragment.page1" 11android:background="@drawable/back"> 12 13<ImageView 14 android:layout_width="wrap_content" 15 android:layout_height="wrap_content" 16 android:id="@+id/imageView" 17 android:background="@drawable/tnm" 18 android:layout_alignParentRight="true" 19 android:layout_alignParentEnd="true" 20 android:layout_alignParentLeft="true" 21 android:layout_alignParentStart="true" /> 22 23<TextView 24 android:layout_width="wrap_content" 25 android:layout_height="wrap_content" 26 android:text="New Text" 27 android:id="@+id/name" 28 android:layout_marginTop="39dp" 29 android:textSize="25dp" 30 android:layout_alignParentTop="true" 31 android:layout_centerHorizontal="true" /> 32 33<TextView 34 android:layout_width="wrap_content" 35 android:layout_height="wrap_content" 36 android:text="Todays Plan....." 37 android:id="@+id/textView2" 38 android:textSize="35dp" 39 android:textStyle="normal|italic" 40 android:theme="@style/AlertDialog.AppCompat.Light" 41 android:layout_below="@+id/Date" 42 android:layout_centerHorizontal="true" /> 43 44<ImageButton 45 android:layout_width="100px" 46 android:layout_height="100px" 47 android:id="@+id/imageButton" 48 android:background="@drawable/unnamed" 49 android:layout_above="@+id/imageButton3" 50 android:layout_alignParentRight="true" 51 android:layout_alignParentEnd="true" 52 android:adjustViewBounds="true" /> 53 54<ImageButton 55 android:layout_width="100px" 56 android:layout_height="100px" 57 android:id="@+id/imageButton2" 58 android:background="@drawable/icon256" 59 android:layout_alignParentBottom="true" 60 android:layout_alignParentRight="true" 61 android:layout_alignParentEnd="true" /> 62 63<ImageButton 64 android:layout_width="100px" 65 android:layout_height="100px" 66 android:id="@+id/imageButton3" 67 android:background="@drawable/facebook" 68 android:layout_above="@+id/imageButton2" 69 android:layout_alignParentRight="true" 70 android:layout_alignParentEnd="true" /> 71 72<ImageButton 73 android:layout_width="100px" 74 android:layout_height="100px" 75 android:id="@+id/voice" 76 android:background="@android:drawable/presence_audio_away" 77 android:layout_above="@+id/imageButton" 78 android:layout_alignParentRight="true" 79 android:layout_alignParentEnd="true" 80 android:nestedScrollingEnabled="false" /> 81 82<ImageButton 83 android:layout_width="wrap_content" 84 android:layout_height="wrap_content" 85 android:id="@+id/imageButton4" 86 android:layout_alignBottom="@+id/imageButton2" 87 android:layout_alignParentLeft="true" 88 android:layout_alignParentStart="true" 89 android:src="@android:drawable/ic_menu_preferences" 90 android:layout_below="@+id/imageButton3" 91 android:layout_toStartOf="@+id/textView2" 92 android:layout_toLeftOf="@+id/textView2" /> 93 94 <TextView 95 android:layout_width="wrap_content" 96 android:layout_height="wrap_content" 97 android:id="@+id/Date" 98 android:textSize="35dp" 99 android:textStyle="normal|italic" 100 android:theme="@style/AlertDialog.AppCompat.Light" 101 android:layout_below="@+id/name" 102 android:layout_toRightOf="@+id/imageButton4" 103 android:layout_toEndOf="@+id/imageButton4" 104 android:text="22222222" /> 105 106</RelativeLayout> 107
Main3activity.java(スワイプを動かしているコード)
java
1 2 3 4import android.app.Activity; 5import android.content.Context; 6import android.os.Bundle; 7import android.support.v4.view.PagerAdapter; 8import android.support.v4.view.ViewPager; 9import android.view.LayoutInflater; 10import android.view.View; 11import android.view.ViewGroup; 12 13public class Main3Activity extends Activity { 14 @Override 15 public void onCreate(Bundle savedInstanceState) { 16 super.onCreate(savedInstanceState); 17 setContentView(R.layout.activity_main3); 18 19 ViewPager mViewPager = (ViewPager) findViewById(R.id.viewpager); 20 PagerAdapter mPagerAdapter = new MyPagerAdapter(); 21 mViewPager.setAdapter(mPagerAdapter); 22 23 24 } 25 26 private class MyPagerAdapter extends PagerAdapter { 27 @Override 28 public Object instantiateItem(ViewGroup container, int position) { 29 // レイアウトファイル名を配列で指定します。 30 int[] pages = {R.layout.activity_page1, R.layout.activity_page2, R.layout.activity_page3}; 31 32 LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE); 33 34 View layout; 35 layout = inflater.inflate(pages[position], null); 36 ((ViewPager) container).addView(layout); 37 return layout; 38 } 39 40 @Override 41 public void destroyItem(ViewGroup container, int position, Object object) { 42 ((ViewPager) container).removeView((View) object); 43 } 44 45 @Override 46 public int getCount() { 47 // ページ数を返します。 48 return 3; 49 } 50 51 @Override 52 public boolean isViewFromObject(View view, Object object) { 53 return view.equals(object); 54 } 55 } 56 57} 58 59
###試したこと
Log.d()により処理の通過を調べましたがlogcatへの表示が確認できませんでした(page1.javaの「・・・・・*」部分)
###補足情報(言語/FW/ツール等のバージョンなど)
java
androidstudio
xml
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2017/03/28 04:29
2017/03/28 04:39 編集
2017/03/28 04:54
2017/03/28 05:04
2017/03/28 05:48 編集
2017/03/28 05:47
2017/03/28 06:09 編集
2017/03/28 06:13