lundi 23 février 2015

Custom Expandable ListView issue with child view


I have custom expandable list view ,in which parent view contains one text view and button.When click on parent button a custom child view appears and that contains another button and 3 edit texts.When click on first Edittext in child view a datepicker dialog will appear.My problem is I am not able to set the date picker values to the edit text , and also get the edit text values on child view button click didnt return any value. Can someone help me please?


Activity.java


private void prepareListData() { listDataHeader = new ArrayList(); listDataChild = new HashMap>();



// Adding parent data
listDataHeader.addAll(selectdMedicines);
int count = listDataHeader.size();
ArrayList<String> child=new ArrayList<String>();
for (int i = 0; i < count; i++) {
child.add("med"+i);
}

for (int i = 0; i < count; i++) {
List<String> name = new ArrayList<String>();
listDataChild.put(listDataHeader.get(i), name);
name.add("Medicine Info");
}

listAdapter = new ExpandableListAdapter(MyMedication.this,
listDataHeader, listDataChild);

// setting list adapter
expListView.setAdapter(listAdapter);
}


ExpandableListAdapter.java


@Override public View getChildView(int groupPosition, final int childPosition, boolean isLastChild, View convertView, ViewGroup parent) {



child=convertView;
final String childText = (String) getChild(groupPosition, childPosition);

final int posi = groupPosition;
if (convertView == null) {
LayoutInflater infalInflater = (LayoutInflater) this._context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = infalInflater.inflate(R.layout.list_item, null);
}

TextView txtListChild = (TextView) convertView
.findViewById(R.id.textEx);
txtListChild.setText(childText);

editMedDt = (EditText) convertView
.findViewById(R.id.medstrdt);
editDose = (EditText) convertView
.findViewById(R.id.dose);
editFreq = (EditText) convertView
.findViewById(R.id.frequency);

ImageView childSave = (ImageView) convertView
.findViewById(R.id.imgSave);
editMedDt.setOnClickListener(new OnClickListener() {

@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
InputMethodManager imm = (InputMethodManager) _context.getSystemService(Context.INPUT_METHOD_SERVICE);
imm.toggleSoftInput(InputMethodManager.HIDE_IMPLICIT_ONLY, 0);
Toast.makeText(_context, "start dt", Toast.LENGTH_LONG).show();
// ((Activity) ExpandableListAdapter.this._context)
//((Activity) ExpandableListAdapter.this._context).showDialog(1);
showDtDialog();
}
});
childSave.setOnClickListener(new OnClickListener() {

@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
// Toast.makeText(_context, "" + posi, Toast.LENGTH_LONG).show();
medName=_listDataHeader.get(posi);
medStrDt=editMedDt.getText().toString();
dose=editDose.getText().toString();
frequency=editFreq.getText().toString();
Toast.makeText(_context, medName +"\n"+ medStrDt+"\n"+dose+"\n"+frequency, Toast.LENGTH_LONG).show();

}
});

return convertView;
}




Aucun commentaire:

Enregistrer un commentaire