剛剛做了一個按鈕,點擊事件打開一個網頁鏈接,在這個佈局上有多個按鈕。現在我想複製第一個按鈕的事件以將其用於其他人。但是當我複製代碼並將名稱替換爲另一個按鈕時,我收到了一些錯誤。問題是什麼?;試圖複製點擊事件
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;
}
}
這不是Android的吳 – Frogger