Ich habe erweiterbare listview, die den editedtext als Kind enthalten und unterhalb dieser ExpandableListView ich habe Schaltfläche, wenn Benutzer auf Schaltfläche klicken, dann möchte ich Text von EditText und speichern in Zeichenfolge, die ich habe in getChildView VerfahrenWie man Text von EditText in erweiterbarer ListView
unter Code versuchtMyAdapter
public class ExListAdapter extends BaseExpandableListAdapter {
private Activity context;
private Map<String, List<String>> collections;
private ArrayList<ListDetails> listItem;
private TextView txtOk;
public ExListAdapter(Activity context, ArrayList<ListDetails> listItem,
Map<String, List<String>> collections, TextView txtOk) {
this.context = context;
this.collections = collections;
this.listItem = listItem;
this.txtOk = txtOk;
}
public Object getChild(int groupPosition, int childPosition) {
return 1;
}
public long getChildId(int groupPosition, int childPosition) {
return childPosition;
}
@Nullable
public View getChildView(final int groupPosition, final int childPosition,
boolean isLastChild, @Nullable View convertView, ViewGroup parent) {
LayoutInflater inflater = context.getLayoutInflater();
if (convertView == null) {
convertView = inflater.inflate(R.layout.list_child, null);
}
etChild = (EditText) convertView.findViewById(R.id.etChild);
txtOk.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
etChild.addTextChangedListener(new TextWatcher() {
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
// TODO Auto-generated method stub
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
// TODO Auto-generated method stub
}
@Override
public void afterTextChanged(Editable s) {
// TODO Auto-generated method stub
System.out.println("Value : " + childPosition + etChild.getText().toString());
Toast.makeText(context, etChild.getText().toString() + "...", Toast.LENGTH_SHORT).show();
}
});
etChild.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
v.getParent().requestDisallowInterceptTouchEvent(true);
switch (event.getAction() & MotionEvent.ACTION_MASK) {
case MotionEvent.ACTION_UP:
v.getParent().requestDisallowInterceptTouchEvent(false);
break;
}
return false;
}
});
etChild.addTextChangedListener(new TextWatcher() {
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
// TODO Auto-generated method stub
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
// TODO Auto-generated method stub
}
@Override
public void afterTextChanged(Editable s) {
// TODO Auto-generated method stub
System.out.println("Value : " + childPosition + etChild.getText().toString());
Toast.makeText(context, etChild.getText().toString() + "...", Toast.LENGTH_SHORT).show();
}
});
return convertView;
}
public int getChildrenCount(int groupPosition) {
return 1;
}
public Object getGroup(int groupPosition) {
return listItem.get(groupPosition).getValue();
}
public int getGroupCount() {
return listItem.size();
}
public long getGroupId(int groupPosition) {
return groupPosition;
}
@Nullable
public View getGroupView(final int groupPosition, boolean isExpanded,
@Nullable View convertView, ViewGroup parent) {
try {
if (convertView == null) {
LayoutInflater infalInflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = infalInflater.inflate(R.layout.list_group,
null);
}
TextView txtName = (TextView) convertView.findViewById(R.id.txtName);
RelativeLayout rlList = (RelativeLayout) convertView.findViewById(R.id.rlList);
txtName.setText(mArr.get(groupPosition).getValue());
} catch (Exception e) {
Logs.d("view- ExListAdapter", e, getClass().getSimpleName());
}
return convertView;
}
public boolean hasStableIds() {
return true;
}
public boolean isChildSelectable(int groupPosition, int childPosition) {
return true;
}
@Override
public void onGroupCollapsed(int groupPosition) {
try {
} catch (Exception e) {
}
super.onGroupCollapsed(groupPosition);
}
}
aber alle Zeit wird es immer leer, bitte guyz Hilfe, um es zu lösen !!!
haben Sie nicht einfach Text wie diesem erhalten "etChild.getText(). ToString()"? ohne "addTextChangedListener"? –
Ich habe es in Toast versucht, aber es zeigt Null !!! –
Ich denke, das Problem ist woanders. Könnten Sie bitte den Code Ihres Adapters teilen? –