這更像是一個設計問題,以及如何設計應用程序。我一直有與片段的樂趣,但有一點是沒有任何意義的,我是這樣的:Android碎片和邏輯應用程序設計
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
page = getArguments().getInt("someInt", 2);
Button btnOne = (Button) getView().findViewById(R.id.one);
btnOne.setOnClickListener(new Button.OnClickListener() {
public void onClick(View v) {
String currentText = getScreen().getText().toString();
currentText += "1";
getScreen().setText(currentText);
}
});
}
// Inflate the view for the fragment based on layout XML
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.standard_calculator, container, false);
return view;
}
/** Return the screen TextView object for manipulation
* @return screen
*/
public TextView getScreen() {
return screen;
}
畫面標題是該類中的私有變量,這是不是整個類,但只是部分,我需要幫助我的問題。至少會有15個左右的按鈕來操縱屏幕,並且它不像是一種很好的做法,並將它們全部放在onCreate方法中,我想知道是否將它們放在另一個類中是更好的設計讓片段中的方法對片段的生命週期更具體,儘管可以說片段使用了按鈕,因此應該是類的一部分。也許需要「初始化」方法。
我一直希望有人能夠指導我設計模式或思考應用程序設計的邏輯思路,這是完全不同的。
非常感謝。
我也意識到這會崩潰,因爲我在創建之前引用視圖...但請堅持原始點。 – user2405469