現在Android Studioを使用して、動的なボタン生成とそのボタンを使用したClickイベントの実装をしようとしているのですが、onClickメソッドに入ることがなく困っています。
解決方法はないでしょうか?
public class Main2Activity extends AppCompatActivity implements View.OnClickListener { public Button button1,button2,button13; ScrollView scrollView; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); TextView textView = new TextView(this); scrollView = new ScrollView(this); scrollView.setTranslationY(500); // View に ScrollView を設定 setContentView(R.layout.activity_main); //View view = this.getLayoutInflater().inflate(R.layout.activity_main, null); addContentView(scrollView, new LinearLayout.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.FILL_PARENT)); LinearLayout linearLayout = new LinearLayout(this); linearLayout.setOrientation(LinearLayout.VERTICAL); // ScrollView に LinearLayout を追加 scrollView.addView(linearLayout); // 追加したいView // LinearLayoutにviewを追加する button1 = new Button(this); button1.setTextSize(50); button1.setText("A"); button1.setTag(1); linearLayout.addView(button1); linearLayout.setBackgroundColor(Color.rgb(0, 0, 0)); button2 = new Button(this); button2.setTextSize(50); button2.setText("B"); linearLayout.addView(button2); Button button3 = new Button(this); button3.setTextSize(50); button3.setText("C"); linearLayout.addView(button3); textView.setText("Test TextView"); textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 50); linearLayout.addView(textView, new LinearLayout.LayoutParams(ActionBar.LayoutParams.WRAP_CONTENT, ActionBar.LayoutParams.WRAP_CONTENT)); } @Override public void onClick(View v) { Log.e("Button","Button"); switch(v.getTag().toString()){ case "1" : Log.e("Button","1"); scrollView.setTranslationY(300); break; } } }

回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。