java视图充气器出现故障
构建用于膨胀xml的自定义视图。 一切正常,只是当选择自定义视图时,也会选择所有其他膨胀自定义视图的视图。我真的不知道问题出在哪里。下面是这个片段
public class DJV_DropDown extends LinearLayout {
private UI_Model ui_models;
private String[] items;
private ArrayAdapter itemAdapter;
private UI_Object ui_object;
public void setUi_object(UI_Object ui_object) {
this.ui_object = ui_object;
}
public UI_Object getUi_object() {
return ui_object;
}
public final void setViewAttribute(UI_Object ui_object) {
ui_models = new AttributeDefiner().AttributeReader(ui_object.getUi_spec(), ui_object.getStepData(), ui_object.getName());
setUi_object(ui_object);
}
public final void setDefaultAttribute() {
if (getUi_object().getUi_spec().getParameterMode().equalsIgnoreCase("entity")) {
getUi_object().setParameterMode(true);
String entityString = getUi_object().getUi_singleField().getEntitySource();
UI_Entity entity = new UI_Entity(entityString);
ArrayList<Entity> entityArrayList = Entity.getAllEntityByName(getUi_object().getContext(), entity.getName());
getUi_object().setEntityObject(entityArrayList);
String keep = "";
for (int entityIndex = 0; entityIndex < entityArrayList.size(); entityIndex++) {
try {
JSONObject jsonObject = new JSONObject(entityArrayList.get(entityIndex).getValue());
keep = jsonObject.optString("::DisplayName::") + ",";
} catch (JSONException e) {
e.printStackTrace();
}
}
if (!keep.trim().isEmpty()) {
items = keep.substring(0, keep.length() - 1).split(",");
textView.setText(items[0]);
} else {
items = new String[0];
}
} else {
items = getUi_object().getUi_singleField().getSourceContent().split(",");
textView.setText(items[0]);
}
}
public final UI_Model getCustomViewAttribute() {
return ui_models;
}
public DJV_DropDown(Context context) {
super(context);
}
public DJV_DropDown(Context context, UI_Object ui_object) {
super(context);
initialise();
setViewAttribute(ui_object);
setDefaultAttribute();
}
TextView textView;
LinearLayout rootLinearLayout;
static int id = 0;
private void initialise() {
LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
inflater.inflate(R.layout.djv_dropdown, this);
textView = (TextView) findViewById(R.id.text);
rootLinearLayout = (LinearLayout) findViewById(R.id.root);
rootLinearLayout.setId(id);
id++; //changed the id because i initially thought the problem was a a result of more than one custom view sharing the same id
}
}
已膨胀的xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:安卓="http://schemas.安卓.com/apk/res/安卓"
安卓:id="@+id/root"
安卓:layout_width="match_parent"
安卓:background="@drawable/drop_down"
安卓:padding="12dp"
安卓:layout_height="wrap_content"
安卓:orientation="horizontal">
<TextView
安卓:layout_weight="1"
安卓:orientation="vertical"
安卓:layout_margin="5dp"
安卓:gravity="center_vertical"
安卓:textSize="16dp"
安卓:text="uyyu"
安卓:id="@+id/text"
安卓:textColor="#000"
安卓:layout_width="match_parent"
安卓:layout_height="wrap_content">
</TextView>
<ImageView
安卓:src="@drawable/spinner_down"
安卓:background="@安卓:color/transparent"
安卓:layout_width="wrap_content"
安卓:layout_height="match_parent" />
</LinearLayout>
共 (0) 个答案