渲染 SortableTableView 的 EditText

Rendering EditText of SortableTableView

我正在使用 SortableTableView 在 android 应用程序中显示 sqlite table。我想添加 table 之外的编辑按钮。如何在按下编辑按钮时为 SortableTableView 启用编辑模式?

我试过这样的代码,但它不起作用。

/* EditDataAdapter.java */

// THIS IS NOT WORKED ???
public void setRenderEditable() {
    int row = 0;
    LinearLayout rowView = new LinearLayout(_tableView.getContext());

    for (int col = 0; col < _tableView.getColumnModel().getColumnCount(); col++) {
        View cellView = getLongPressCellView(row, col, rowView);

        int cellWidth = _tableView.getColumnModel().getColumnWidth(col, _tableView.getWidth());
        LinearLayout.LayoutParams cellLayoutParams = new LinearLayout.LayoutParams(cellWidth, LinearLayout.LayoutParams.WRAP_CONTENT);
        cellView.setLayoutParams(cellLayoutParams);

        _tableView.addView(cellView);
        _tableView.invalidate();
    }
}



/* EditFragment.java */

// Calling EditDataAdapter
ServerSortableTableView tableView = (ServerSortableTableView) rootView.findViewById(R.id.server_table);
if (tableView != null) {
    EditDataAdapter editDataAdapter = new EditDataAdapter(getContext(), ServerDataFactory.readServerList(), tableView);
    tableView.setDataAdapter(editDataAdapter);
}

Button editButton = (Button) rootView.findViewById(R.id.edit_button);
if (editButton != null) {
    editButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (editButton.getText().toString().equals("edit")) {
                editDataAdapter.setRenderEditable(); // This is not worked
                editButton.setText("save");
            } else {
                editButton.setText("edit");
            }
        }
    });
}

我找到了解决问题的方法。我会在这里分享,它可能对其他人有用。

public void setRenderEditable() {
    _tableView.setMinimumWidth(900);
    _tableView.removeViewAt(1);

    int row = 0;
    LinearLayout rowView = new LinearLayout(_tableView.getContext());

    for (int col = 0; col < _tableView.getColumnModel().getColumnCount(); col++) {
        View cellView = getLongPressCellView(row, col, rowView);

        int cellWidth = _tableView.getColumnModel().getColumnWidth(col, _tableView.getWidth());
        LinearLayout.LayoutParams cellLayoutParams = new LinearLayout.LayoutParams(cellWidth, LinearLayout.LayoutParams.WRAP_CONTENT);
        cellView.setLayoutParams(cellLayoutParams);

        rowView.addView(cellView);
    }
    _tableView.addView(rowView, 1);
}