【发布时间】:2019-02-20 20:56:02
【问题描述】:
我想从 listView 制作一个可重复使用的 Listview 控件,其中的列可以被控制,假设我想加载 3 列列表视图,有时是 2 有时是 4。 如何以编程方式控制列表视图的列和行。根据我的 json 值,我将显示列表。 另外我想让一些列也可以编辑。这也需要由代码级别控制
这是我开始的代码:
import android.content.Context;
import android.graphics.Color;
import android.graphics.PorterDuff;
import org.json.JSONArray;
import org.json.JSONObject;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
public class LayoutAdvancedList extends ListView {
private String m_name;
private int m_editMask = 0;
private int m_EditedRowIndex = 0;
private int m_EditedFieldIndex = 0;
public String getName() {
return m_name;
}
public void setName(String name) {
this.m_name = name;
}
public void setMaxLength(final int maxLength) {
if (maxLength > 0) {
// super.setFilters(new InputFilter[]{new InputFilter.LengthFilter(maxLength)});
} else {
// super.setFilters(new InputFilter[]{});
}
}
public void setReadOnly(final boolean readOnly) {
super.setFocusable(!readOnly);
super.setFocusableInTouchMode(!readOnly);
super.setClickable(!readOnly);
super.setLongClickable(!readOnly);
// super.setCursorVisible(!readOnly);
}
public LayoutAdvancedList(Context context) {
super(context);
LayoutInitialize(context);
}
public LayoutAdvancedList(Context context, AttributeSet attrs) {
super(context, attrs);
LayoutInitialize(context);
}
public LayoutAdvancedList(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
LayoutInitialize(context);
}
@Override
public void setEnabled(boolean enabled) {
super.setEnabled(enabled);
if (enabled) {
this.getBackground().setColorFilter(null);
} else {
this.getBackground().setColorFilter(Color.GRAY, PorterDuff.Mode.MULTIPLY);
}
}
【问题讨论】:
-
你能贴出你想要实现的UI快照
-
你为什么不使用回收站视图?