我正在使用一个我有一个ExpandableListView的应用程序,在这里也有一些childViews。在每个ChildView中,当我更改这些edittext中的值时,我有很多edittexts,它会产生问题。当我尝试打开键盘时点击它未打开。我想更改每个edittext的值,并将这些值反映到Expandableview。
这是我的代码:
公共类PatientMedicationExpandableAdapter扩展BaseExpandableListAdapter {
private Context _context;
private List<String> _listDataHeader;
private TreeMap<String, List<String>> _listDataChild;
private View view;
private TextView editText;
private static int count=0;
private int[] images;
public PatientMedicationExpandableAdapter(Context context, List<String> listDataHeader,
TreeMap<String, List<String>> listChildData, int[] images) {
this._context = context;
this._listDataHeader = listDataHeader;
this._listDataChild = listChildData;
this.images=images;
}
@Override
public Object getChild(int groupPosition, int childPosititon) {
return this._listDataChild.get(this._listDataHeader.get(groupPosition))
.get(childPosititon);
}
@Override
public long getChildId(int groupPosition, int childPosition) {
return childPosition;
}
@Override
public void onGroupExpanded(int groupPosition) {
super.onGroupExpanded(groupPosition);
}
@Override
public void onGroupCollapsed(int groupPosition) {
super.onGroupCollapsed(groupPosition);
}
public Context get_context() {
return _context;
}
@Override
public View getChildView(int groupPosition, final int childPosition,
boolean isLastChild, View convertView, ViewGroup parent) {
final ViewHolder holder = new ViewHolder();
final String childText = (String) getChild(groupPosition, childPosition);
if (convertView == null) {
LayoutInflater infalInflater = (LayoutInflater) this._context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = infalInflater.inflate(R.layout.patient_expadable_medication_child_item, null);
view = convertView;
}
holder.txtListChild = (TextView) convertView.findViewById(R.id.lblListItem);
holder.editchild = (ImageView) convertView.findViewById(R.id.editchild);
holder.editchild.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
holder.editchild.post(
new Runnable() {
public void run() {
InputMethodManager inputMethodManager = (InputMethodManager) _context.getSystemService(_context.INPUT_METHOD_SERVICE);
inputMethodManager.toggleSoftInputFromWindow(holder.editchild.getApplicationWindowToken(), InputMethodManager.SHOW_FORCED, 0);
holder.editchild.requestFocusFromTouch();
}
});
}
});
UiUtils.applyTypceFace(_context,holder.txtListChild);
holder.txtListChild.setText(childText);
return convertView;
}
@Override
public int getChildrenCount(int groupPosition) {
return this._listDataChild.get(this._listDataHeader.get(groupPosition))
.size();
}
@Override
public Object getGroup(int groupPosition) {
return this._listDataHeader.get(groupPosition);
}
@Override
public int getGroupCount() {
return this._listDataHeader.size();
}
@Override
public long getGroupId(int groupPosition) {
return groupPosition;
}
@Override
public View getGroupView(final int groupPosition, final boolean isExpanded,
View convertView, final ViewGroup parent) {
final ViewHolder holder = new ViewHolder();
final View groupView=convertView;
final String headerTitle = (String) getGroup(groupPosition);
if (convertView == null) {
LayoutInflater infalInflater = (LayoutInflater) this._context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = infalInflater.inflate(R.layout.patient_exapandable_medication_group_item, null);
}
holder.editContentImageView=(ImageView)convertView.findViewById(R.id.editContentImageView);
holder.editContentImageView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
LayoutInflater inflater = (LayoutInflater)_context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
final View view = inflater.inflate(R.layout.test, null);
final LinearLayout ll=(LinearLayout)view.findViewById(R.id.LinearLayout1);
final Dialog d=new Dialog(_context);
d.requestWindowFeature(Window.FEATURE_NO_TITLE);
d.setContentView(view);
d.setCanceledOnTouchOutside(false);
d.setCancelable(false);
try {
for (String key : _listDataChild.keySet()) {
List<String> value = _listDataChild.get(key);
for (String val : value) {
EditText et = new EditText(_context);
et.setText(val);
et.setMinLines(1);
et.setMaxLines(3);
ll.addView(et);
System.out.println(val);
}
}
}catch (Exception e){
System.out.println("Exception "+e);
}
(view.findViewById(R.id.add_ok)).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
}
});
(view.findViewById(R.id.new_Field)).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
editText= new TextView(_context);
editText.requestFocus();
editText.setId(Integer.valueOf(count));
ll.addView(editText);
d.setContentView(view);
count++;
}
});
((TextView)view.findViewById(R.id.add_no)).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
d.dismiss();
}
});
d.show();
}
});
holder.lblListHeader = (TextView) convertView.findViewById(R.id.lblListHeader);
holder.lblListHeader.setText(headerTitle);
UiUtils.applyTypceFace(_context,holder.lblListHeader);
holder.imageView=(ImageView)convertView.findViewById(R.id.iconImageView
);
holder.imageView.setImageDrawable(_context.getResources().getDrawable(images[groupPosition]));
return convertView;
}
@Override
public boolean hasStableIds() {
return false;
}
@Override
public boolean isChildSelectable(int groupPosition, int childPosition) {
return true;
}
static class ViewHolder {
private TextView txtListChild;
private TextView lblListHeader;
private ImageView imageView;
private ImageView editContentImageView;
private ImageView editchild;
}
}