Tôi có một đoạn mà tôi cần hiển thị trên màn hình. Tôi muốn có thể sử dụng InjectView
để chèn các phần tử giao diện người dùng của mình. InjectView hoạt động tốt trên các hoạt động vì chế độ xem (xml) được đặt trong thời gian onCreate
, tuy nhiên trên các phần, chế độ xem được đặt trên onCreatView
.Android & RoboGuice - Tiêm chế độ xem trên mảnh vỡ?
Vậy có cách nào để sử dụng InjectView trên phân đoạn không? Tôi biết rằng tôi có thể sử dụng để tìm findViewbyId mỗi yếu tố, nhưng tôi thay vì sử dụng InjectView
public class ProfileFragment extends RoboDialogFragment {
@InjectView(R.id.commentEditText)
protected EditText commentEditText;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// I get a null pointer exception here
commentEditText.setText("Some comment");
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.profile , container, false);
// I get a null pointer exception here
commentEditText.setText("Some comment");
return view;
}
}
hãy sao vấn đề Roboguice (http://code.google.com/ p/roboguice/issues/detail? id = 160 & q = contentview) để hiển thị các nhà phát triển này nên được thêm – Diederik