ここに私のメインコードがあります:
プライベート クラス DetailExpandAdapter は BaseExpandableListAdapter を拡張します{
private Drawable isNull;
public DetailExpandAdapter(){
isNull = getResources().getDrawable(R.drawable.star);
//调用setCompoundDrawables时,必须调用Drawable.setBounds()方法,否则图片不显示
isNull.setBounds(0, 0, isNull.getMinimumWidth(), isNull.getMinimumHeight());
}
@Override
public int getGroupCount() {
return group.size();
}
@Override
public int getChildrenCount(int groupPosition) {
return child.get(groupPosition).size();
}
@Override
public Object getGroup(int groupPosition) {
return group.get(groupPosition);
}
@Override
public Object getChild(int groupPosition, int childPosition) {
return child.get(groupPosition).get(childPosition);
}
@Override
public long getGroupId(int groupPosition) {
return groupPosition;
}
@Override
public long getChildId(int groupPosition, int childPosition) {
return groupPosition * 100 + childPosition;
}
@Override
public boolean hasStableIds() {
return false;
}
@Override
public View getGroupView(int groupPosition, boolean isExpanded,
View convertView, ViewGroup parent) {
ViewHolder holder = null;
if(convertView == null){
TextView text = new TextView(Update.this);
text.setGravity(Gravity.CENTER_VERTICAL | Gravity.LEFT);
text.setTextSize(15);
text.setTextColor(Color.BLACK);
AbsListView.LayoutParams lp;
lp = new AbsListView.LayoutParams(
ViewGroup.LayoutParams.FILL_PARENT, ObjectUtils.getFontHeight(text.getTextSize()) * 2);
text.setLayoutParams(lp);
text.setBackgroundResource(R.drawable.expanditemgroup);
convertView = text;
holder = new ViewHolder();
holder.key = (TextView)convertView;
convertView.setTag(holder);
}else {
holder = (ViewHolder)convertView.getTag();
}
((TextView)convertView).setText(group.get(groupPosition));
holder.key.setText(group.get(groupPosition));
return convertView;
}
@Override
public View getChildView(final int groupPosition, final int childPosition,
boolean isLastChild, View convertView, ViewGroup parent) {
final ViewHolder holder;
final ConfigItem item=child.get(groupPosition).get(childPosition);
if(convertView == null ){
holder = new ViewHolder();
convertView = LayoutInflater.from(Update.this).inflate(R.layout.queryitem, null);
holder.isused = (CheckBox)convertView.findViewById(R.id.isused);
holder.key = (TextView)convertView.findViewById(R.id.key);
holder.edit_value = (EditText)convertView.findViewById(R.id.editvalue);
holder.edit_value.setVisibility(View.VISIBLE);
holder.text_value = (EditText)convertView.findViewById(R.id.textvalue);
holder.btn = (ImageView)convertView.findViewById(R.id.set);
holder.isused.setVisibility(View.GONE);
LayoutParams params = holder.key.getLayoutParams();
params.width = Update.this.getWindowManager().getDefaultDisplay().getWidth()/4;
holder.key.setLayoutParams(params);
convertView.setTag(holder);
}else{
holder = (ViewHolder)convertView.getTag();
}
holder.edit_value.clearFocus();
holder.key.setText(item.getColumnDescribe() + ":");
//增加必输项图标
if (!item.isNull()) {
holder.key.setCompoundDrawables(isNull, null, null, null);
}else{
holder.key.setCompoundDrawables(null, null, null, null);
}
//编辑框监听及赋值
holder.edit_value.setOnFocusChangeListener(new OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus) {
if(!hasFocus){
item.setDisplayValue(((EditText)v).getText().toString());
item.setValue(((EditText)v).getText().toString());
}
}
});
if(item.isList()){
holder.edit_value.setText(item.getDisplayValue());
holder.text_value.setText(item.getDisplayValue());
}else if(item.getColumnType().equals("VIRTUALBUTTON")){
holder.edit_value.setText(item.getColumnDescribe());
holder.text_value.setText(item.getColumnDescribe());
}else{
holder.edit_value.setText(item.getValue());
holder.text_value.setText(item.getValue());
}
if(item.getColumnType().equalsIgnoreCase("number")){
//only number is allowed when the columntype is number
holder.text_value.setInputType(InputType.TYPE_CLASS_NUMBER);
holder.edit_value.setInputType(InputType.TYPE_CLASS_NUMBER);
holder.text_value.setSingleLine(true);
holder.text_value.setLines(1);
holder.edit_value.setSingleLine(true);
holder.edit_value.setLines(1);
} else if(item.getColumnType().equalsIgnoreCase("TEXTAREA")){
holder.text_value.setInputType(InputType.TYPE_CLASS_TEXT);
holder.edit_value.setInputType(InputType.TYPE_CLASS_TEXT);
holder.text_value.setSingleLine(false);
holder.text_value.setMinLines(3);
holder.edit_value.setSingleLine(false);
holder.edit_value.setMinLines(3);
} else{
holder.text_value.setInputType(InputType.TYPE_CLASS_TEXT);
holder.edit_value.setInputType(InputType.TYPE_CLASS_TEXT);
holder.text_value.setSingleLine(true);
holder.text_value.setLines(1);
holder.edit_value.setSingleLine(true);
holder.edit_value.setLines(1);
}
if(item.isText()){
holder.btn.setVisibility(View.GONE);
//是否可编辑
if(!item.isUpdate()){
holder.text_value.setBackgroundDrawable(getResources().getDrawable(R.drawable.touming));
holder.text_value.setEnabled(false);
holder.text_value.setFocusable(false);
holder.text_value.setFocusableInTouchMode(false);
holder.text_value.setVisibility(View.VISIBLE);
holder.edit_value.setVisibility(View.GONE);
}else{
holder.edit_value.setEnabled(true);
holder.edit_value.setFocusable(true);
holder.edit_value.setFocusableInTouchMode(true);
holder.edit_value.setVisibility(View.VISIBLE);
holder.text_value.setVisibility(View.GONE);
}
}else if(item.isList()){ //下拉框
holder.btn.setVisibility(View.VISIBLE);
if(!item.isUpdate()){
holder.btn.setVisibility(View.GONE);
}else{
holder.btn.setVisibility(View.VISIBLE);
}
holder.edit_value.setVisibility(View.GONE);
holder.text_value.setVisibility(View.VISIBLE);
holder.btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
showGroupPosition = groupPosition;
showChildPosition = childPosition;
Intent intent = new Intent(Update.this, QueryDict.class);
intent.putExtra("class", ConstVars.DATASOURCE_LIST_DICT);
intent.putExtra("action", ConstVars.LN_DICT_ACTION);
intent.putExtra(ConstVars.DICT_ITEM, item);
intent.putExtra("fromClass", Update.this.getComponentName().getClassName());
startActivityForResult(intent, 1);
}
});
}else if (child.get(groupPosition).get(childPosition).isDate()) {
holder.btn.setVisibility(View.VISIBLE);
if(!item.isUpdate()){
holder.btn.setVisibility(View.GONE);
}else{
holder.btn.setVisibility(View.VISIBLE);
}
holder.edit_value.setVisibility(View.GONE);
holder.text_value.setVisibility(View.VISIBLE);
holder.btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
showGroupPosition = groupPosition;
showChildPosition = childPosition;
Intent intent=new Intent(Update.this,DTPickerDialog.class);
intent.putExtra("fromClass", Update.this.getComponentName().getClassName());
Update.this.startActivityForResult(intent, 2);
}
});
}else if(child.get(groupPosition).get(childPosition).isVitual()){
holder.btn.setVisibility(View.VISIBLE);
if(!item.isUpdate()){
holder.btn.setVisibility(View.GONE);
}else{
holder.btn.setVisibility(View.VISIBLE);
}
if(child.get(groupPosition).get(childPosition).getColumnType().equalsIgnoreCase("VIRTUALBUTTON")
&& child.get(groupPosition).get(childPosition).getLinkObject().getFuncName().equals("showFileField")){
if(item.getValue()!=null&&!"".equals(item.getValue())){
holder.btn.setVisibility(View.VISIBLE);
}else{
holder.btn.setVisibility(View.GONE);
}
}
holder.edit_value.setVisibility(View.GONE);
holder.text_value.setVisibility(View.VISIBLE);
holder.text_value.setText(item.getName());
holder.btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if(child.get(groupPosition).get(childPosition).getColumnType().equalsIgnoreCase("USERPICKER")){
Intent intent=new Intent(Update.this, UserSelected.class);
showChildPosition=childPosition;
showGroupPosition=groupPosition;
intent.putExtra(ConstVars.USERCHOICE_SELECTUSER, item);
intent.putExtra("type", "13");
//
startActivityForResult(intent, 10); }else if(child.get(groupPosition).get(childPosition).getColumnType().equalsIgnoreCase("VIRTUALBUTTON") && child.get(groupPosition).get(childPosition).getLinkObject().getFuncName().equals(" showFileField")){//付属品 インテント Intent=new Intent(Update.this, Attachment.class); インテント.putExtra("id", item.getValue());
startActivity(intent);
}
}
});
}
return convertView;
}
@Override
public boolean isChildSelectable(int groupPosition, int childPosition) {
return true;
}
}