##自分は、金沢観光アプリをAndroid Studioでjava言語を利用して作ろうと思ってます。
##完成形は、
######1 金沢へようこそ!左にスワイプしてください!と表記させる
######2 左にスワイプするとボタンが二つ生成され、どちらのボタンを押したかによって処理を変える([観光地リストへ]というボタンを押すと観光地の選択肢がラジオボタンで与えられる、[トップページへ]というボタンを押すと1に戻る。)
######3 観光地の選択肢のラジオボタンを押すと、地図が表示され、現在地、目的地の場所をピンで記す
######4 5秒後音声案内を開始する。
######5 目的地に着いたら、音声案内を終了する。
##といったプログラムを作りたいのですが、2の(「観光地リストへ」というボタンを押すと観光地の選択肢がラジオボタンで与えられる)というところがうまくできません。どなたか原因を教えていただけると助かります。今現在コードは以下のようになってます。
package es.exsample;
import android.app.Activity;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;
import android.view.animation.TranslateAnimation;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;
import android.widget.ViewFlipper;
public class ExSample extends AppCompatActivity {
static final int num = 100;
ViewFlipper vf;
TextView tv1,tv2;
Button bt1,bt2; //ボタン生成
RadioButton rb[] = new RadioButton[4];
RadioGroup rg;
ListView lv; LinearLayout[] ll = new LinearLayout[3]; float x; public void onCreate(Bundle savedInstanceState){ super.onCreate(savedInstanceState); LinearLayout llp = new LinearLayout(this); setContentView(llp); vf = new ViewFlipper(this); tv1 = new TextView(this); tv1.setTextSize(20); tv1.setText("金沢へようこそ!"); tv2 = new TextView(this); tv2.setTextSize(20); tv2.setText("左にフリップしてください"); bt1 = new Button(this); bt1.setText("観光地リストへ"); bt2 = new Button(this); bt2.setText("トップページへ"); for(int i=0; i<rb.length; i++) //ラジオボタンの各要素の生成 rb[i] = new RadioButton(this); rb[0].setText("近江町市場"); //ラジオボタンのテキストの設定 rb[1].setText("東茶屋街"); rb[2].setText("武家屋敷"); rb[3].setText("忍者寺"); rg = new RadioGroup(this); //ラジオグループの生成 for(int i=0; i<rb.length; i++) //ラジオグループにラジオボタンを登録 rg.addView(rb[i]); lv = new ListView(this); ArrayAdapter<String> ad = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, str); lv.setAdapter(ad); ll[0] = new LinearLayout(this); ll[0].addView(tv1); ll[0].addView(tv2); vf.addView(ll[0]); ll[1] = new LinearLayout(this); ll[1].addView(bt1); ll[1].addView(bt2); vf.addView(ll[1]); ll[2] = new LinearLayout(this); ll[2].addView(lv); vf.addView(ll[2]); llp.addView(vf); setContentView(llp); llp.setOnTouchListener(new SampleTouchListener()); bt1.setOnClickListener(new ExSampleClickListener()); //ボタンを押した際のフリップアニメーションの設定 bt2.setOnClickListener(new ExSampleClickListener()); for(int i=0; i<rb.length; i++) rb[i].setOnClickListener(new ExSample.ExSampleClickListener()); //ラジオボタンクリック時のリスナー登録 } class SampleTouchListener implements OnTouchListener{ public boolean onTouch(View v, MotionEvent e){ if(e.getAction() == MotionEvent.ACTION_DOWN){ x = e.getX(); } else if(e.getAction() == MotionEvent.ACTION_UP){ if(x-20 > e.getX()){ TranslateAnimation inanim = new TranslateAnimation(tv1.getWidth(), 0, 0, 0); inanim.setDuration(500); TranslateAnimation outanim = new TranslateAnimation(0,-tv1.getWidth(), 0, 0); outanim.setDuration(500); vf.setInAnimation(inanim); vf.setOutAnimation(outanim); vf.showNext(); } else if(x+20 < e.getX()){ TranslateAnimation inanim = new TranslateAnimation(-tv1.getWidth(), 0, 0, 0); inanim.setDuration(500); TranslateAnimation outanim = new TranslateAnimation(0,tv1.getWidth(), 0, 0); outanim.setDuration(500); vf.setInAnimation(inanim); vf.setOutAnimation(outanim); vf.showPrevious(); } } return true; } } class ExSampleClickListener implements View.OnClickListener { //ボタンを押した際のフリップアニメーション処理 public void onClick(View v){ if(v==bt1) { TranslateAnimation inanim = new TranslateAnimation(tv1.getWidth(), 0, 0, 0); inanim.setDuration(500); TranslateAnimation outanim = new TranslateAnimation(0, -tv1.getWidth(), 0, 0); outanim.setDuration(500); vf.setInAnimation(inanim); vf.setOutAnimation(outanim); vf.showNext(); } else if(v==bt2) { TranslateAnimation inanim = new TranslateAnimation(-tv1.getWidth(), 0, 0, 0); inanim.setDuration(500); TranslateAnimation outanim = new TranslateAnimation(0, tv1.getWidth(), 0, 0); outanim.setDuration(500); vf.setInAnimation(inanim); vf.setOutAnimation(outanim); vf.showPrevious(); } } }
}