ExpandableList in Android For drop down Contact us Form


Drop down Contact us Form in Android



We use expandable list for this....

ContactUs Adapter class
public class ContactUsAdapter extends BaseExpandableListAdapter {
 private LayoutInflater inflater;

 public Context ctxt;
 Typeface myTypeface;

 static class ChildHolder {
  private EditText etName, etEmail, etMessage;
  private Button btnSubmit;
 }

 static class GroupHolder {
  private TextView txtGroupName;
 }

 public ContactUsAdapter(Context context) {

  this.ctxt = context;

  myTypeface = Typeface.createFromAsset(ctxt.getAssets(),
    "fonts/BRADHITC_0.ttf");
  inflater = (LayoutInflater) ctxt
    .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
 }

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

  final ChildHolder holder;

  if (convertView == null) {
   convertView = inflater.inflate(R.layout.contactus, null);
   holder = new ChildHolder();

   holder.etName = (EditText) convertView.findViewById(R.id.etName);
   holder.etEmail = (EditText) convertView.findViewById(R.id.etEmail);
   holder.etMessage = (EditText) convertView
     .findViewById(R.id.etMessage);
   holder.btnSubmit = (Button) convertView
     .findViewById(R.id.btnMailSubmit);
   // holder.txtChildName.setTypeface(myTypeface);
   convertView.setTag(holder);

  } else {
   holder = (ChildHolder) convertView.getTag();
  }
  holder.btnSubmit.setOnClickListener(new OnClickListener() {

   @Override
   public void onClick(View v) {
    
   
  AlertDialog.Builder alertLogout = new AlertDialog.Builder(ctxt);
  alertLogout.setTitle(R.string.app_name);
  alertLogout.setMessage("Mail Successfully Sent!..");
  alertLogout.setPositiveButton("Ok",new DialogInterface.OnClickListener() {
   @Override
   public void onClick(DialogInterface dialog,int which) {
   
   dialog.dismiss();
      }
    });
  alertLogout.show();
    }
    

    
   }
  });

 }

 @Override
 public View getGroupView(int groupPosition, boolean isExpanded,
   View convertView, ViewGroup parent) {
  GroupHolder holder;

  if (convertView == null) {
   convertView = inflater.inflate(R.layout.group_list, null);
   holder = new GroupHolder();

   holder.txtGroupName = (TextView) convertView
     .findViewById(R.id.txtGroupName);
   holder.txtGroupName.setTypeface(myTypeface);
   convertView.setTag(holder);

  } else {
   holder = (GroupHolder) convertView.getTag();
  }

  holder.txtGroupName.setText("Contact Us");
  return convertView;
 }

 @Override
 public Object getChild(int arg0, int arg1) {
  return null;
 }

 @Override
 public long getChildId(int groupPosition, int childPosition) {
  return 0;
 }

 @Override
 public int getChildrenCount(int groupPosition) {
  
  return 1;
 }

 @Override
 public Object getGroup(int groupPosition) {
  return null;
 }

 @Override
 public int getGroupCount() {
  return 1;
 }

 @Override
 public long getGroupId(int groupPosition) {
  return 0;
 }

 @Override
 public boolean hasStableIds() {
  return false;
 }

 @Override
 public boolean isChildSelectable(int groupPosition, int childPosition) {
  return false;
 }





  
Contact Us .xml

   <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <RelativeLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:background="@color/brown" >

        <RelativeLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="5dp"
            android:layout_marginRight="5dp"
            android:layout_marginTop="10dp" >

            <LinearLayout
                android:id="@+id/linear1"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content" >

                <TextView
                    android:id="@+id/textView1"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="Name"
                    android:textColor="@color/black" />

                <EditText
                    android:id="@+id/etName"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginLeft="5dp"
                    android:layout_weight="1"
                    android:ems="10"
                    android:inputType="textPersonName" />

            </LinearLayout>

            <LinearLayout
                android:id="@+id/linear2"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_below="@id/linear1" >

                <TextView
                    android:id="@+id/textView1"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="Email"
                    android:textColor="@color/black" />

                <EditText
                    android:id="@+id/etEmail"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginLeft="5dp"
                    android:layout_weight="1"
                    android:ems="10"
                    android:inputType="textPersonName" />

            </LinearLayout>

            <LinearLayout
                android:id="@+id/linear3"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_below="@id/linear2"
                android:orientation="vertical" >

                <TextView
                    android:id="@+id/textView2"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="Message"
                    android:textColor="@color/black" />

                <EditText
                    android:id="@+id/etMessage"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:inputType="textMultiLine" />
            </LinearLayout>

            <RelativeLayout
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_below="@id/linear3" >

                <Button
                    android:id="@+id/btnMailSubmit"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_centerInParent="true"
                    android:text="Submit" />

            </RelativeLayout>
        </RelativeLayout>

    </RelativeLayout>

</RelativeLayout>

Contactus.xml layout  is inflated in getChildV
iew Method of adapter class..