Tôi có 2 tệp bố cục khác nhau mà tôi muốn sử dụng để sửa đổi cùng một dữ liệu, tôi đã chuyển sang bố cục của mình cho "chế độ xem chỉnh sửa" cho phép người dùng sửa đổi dữ liệu đồ thị và sau đó cho phép họ chuyển về "chế độ xem chi tiết" hiển thị biểu đồ chi tiết (sử dụng thư viện androidplot).Chuyển giữa 2 bố cục trong hoạt động android
Vấn đề của tôi là khi chuyển về "chế độ xem chỉnh sửa", các đường vẽ đồ thị của tôi không còn nữa và chỉ có các trục được vẽ (để bố cục chuyển đổi và onDraw() đang được gọi cho Chế độ xem biểu đồ của tôi). Tất cả mọi thứ được lưu trữ trong cùng một hoạt động vì vậy tôi không hiểu tại sao điều này không hoạt động?
Các dòng được lưu trữ trong chính đối tượng Chế độ xem biểu đồ cần được duy trì liên tục vì nó là biến được lưu trữ trong hoạt động của tôi.
Tôi sử dụng hai phương pháp này để chuyển đổi tệp bố cục khi nhấp vào nút.
public class GraphLibActivity extends Activity {
private Graph graph;
private boolean editView;
private static TextView coordTextView;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
editView = true;
setContentView(R.layout.graphlib);
graph = (Graph) findViewById(R.id.graph);
coordTextView = (TextView)findViewById(R.id.currentCoords);
(lots of calculations)
graph.addLine(gelHistogramPoints, linePaint);
graph.invalidate();
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
if(editView == true){
inflater.inflate(R.menu.activity_menu, menu);
}else{
inflater.inflate(R.menu.detailed_view_menu, menu);
}
return true;
}
public boolean onPrepareOptionsMenu(Menu menu){
menu.clear();
MenuInflater inflater = getMenuInflater();
if(editView == true){
inflater.inflate(R.menu.activity_menu, menu);
}else{
inflater.inflate(R.menu.detailed_view_menu, menu);
}
graph.invalidate();
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle item selection
switch (item.getItemId()) {
case R.id.detailed_view:
editView = false;
setContentView(R.layout.imagegraph);
return true;
case R.id.edit_view:
editView = true;
setContentView(R.layout.editgraph);
return true;
default:
return super.onOptionsItemSelected(item);
}
}
}
Cảm ơn, công trình này tuyệt vời. –
Tôi muốn hiển thị chế độ xem cụ thể mà không đoán nếu bạn đang sử dụng chế độ xem 'tiếp theo' hoặc' đầu tiên': 'vf.setDisplayedChild (vf.indexOfChild (vfChildView))' – derenio
Trong ví dụ của bạn, bạn vẫn phải đặt lại tất cả dữ liệu? Nếu có một textEdit trong cả hai bố trí, và tôi muốn kết hợp thông tin từ hai bố trí, và đặt nó trong một textView trong một bố trí thứ ba, làm thế nào tôi sẽ làm điều đó? –