クリックイベントが発生したボタンを作成してウェブページへのリンクを開きました。このレイアウトには複数のボタンがあります。今度は最初のボタンのイベントを複製して他のボタンにも使用したいと思っています。しかし、私はコードを複製し、他のボタンに名前を置き換えると、私はいくつかのエラーが発生します。何が問題ですか?;クリックイベントを複製しようとしています
public class FourthFragment extends Fragment {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fourth_layout, container, false);
final Button button2 = (Button) view.findViewById(R.id.button2);
button2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://maurick.magister.net"));
startActivity(browserIntent);
}
});
return view;
final Button button3 = (Button) view.findViewById(R.id.button3);
//a red line is showing line above
button3.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://maurickcollege.net"));
startActivity(browserIntent);
}
});
return view;
}
}
はこのアンドロイドあぁじゃないん
用 – Frogger