Skip to main content

Featured

Android studio “SDK tools directory is missing”

Following 2 possible solutions will resolve this problem :  Solution1 : To fix the problem, it was required that I list the path to my corporate PAC file by using  Configure -> "Appearance and Behavior" -> System Settings -> HTTP Proxy . I selected "Automatic proxy configuration url:" Delete your  ~/.Android*  folders (losing all of your settings :/). Run Android Studio. It will show you a welcome wizard where it tries to download the SDK again (and fails due to my rubbish internet). Click the X on the wizard window. That will enable you to get to the normal welcome dialog. Go to Settings->Project Defaults->Project Structure and change the Android SDK location to the correct one. Solution 2 : To fix the problem, it was required that I list the path to my corporate PAC file by using  Configure -> "Appearance and Behavior" -> System Settings -> HTTP Proxy . I selected "Automatic proxy configuration url:&quo

code for Nested listView's(or Inner ListViews) in Android(Means displaying one listview inside other listview)..

//Means this code used for, each row of ListView having individual sub list rows.
//in this i used two .xml files 1-for parent_row and 2-for child_row of list


ExpandableListViewActivityActivity.java :-

package org.sample.ExpandListActivity;

import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseExpandableListAdapter;
import android.widget.Button;
import android.widget.ExpandableListView;
import android.widget.ExpandableListView.OnChildClickListener;
import android.widget.ExpandableListView.OnGroupCollapseListener;
import android.widget.ExpandableListView.OnGroupExpandListener;
import android.widget.TextView;

public class ExpandableListViewActivityActivity extends Activity {
    /**
     * strings for group elements
     */
    static final String arrGroupelements[] = { "India", "Australia", "England","South Africa" };

    /**
     * strings for child elements
     */
    static final String arrChildelements[][] = {
            { "Sachin Tendulkar", "Raina", "Dhoni", "Yuvi" },
            { "Ponting", "Adam Gilchrist", "Michael Clarke" },
            { "Andrew Strauss", "kevin Peterson", "Nasser Hussain" },
            { "Graeme Smith", "AB de villiers", "Jacques Kallis" } };
  
    ExpandableListView expList;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        expList = (ExpandableListView) this.findViewById(R.id.expandableListView1);
      
       
        // this code for adjusting the group indicator into right side of the
        // view
        expList.setGroupIndicator(null);

       
       /* //Important code used to Visible or Hide Lines(Deviders) in between each child/parent row of ListView       
        expList.setGroupIndicator(null);
        expList.setChildIndicator(null);
        expList.setChildDivider(getResources().getDrawable(R.color.greywhite));       
        expList.setDivider(getResources().getDrawable(R.color.white));
        expList.setDividerHeight(2);*/
       
       
        expList.setAdapter(new ExpAdapter(this,expList));

        //below three methods are not important allways,if u want to remove no problem..
        expList.setOnGroupExpandListener(new OnGroupExpandListener() {
            public void onGroupExpand(int groupPosition) {
                Log.e("onGroupExpand", "OK");
            }
        });
        expList.setOnGroupCollapseListener(new OnGroupCollapseListener() {
            public void onGroupCollapse(int groupPosition) {
                Log.e("onGroupCollapse", "OK");
            }
        });
        expList.setOnChildClickListener(new OnChildClickListener() {
            public boolean onChildClick(ExpandableListView parent, View v,
                    int groupPosition, int childPosition, long id) {
                Log.e("OnChildClickListener", "OK");
                return false;
            }
        });
    }

    public int GetDipsFromPixel(float pixels) {
        // Get the screen's density scale
        final float scale = getResources().getDisplayMetrics().density;
        // Convert the dps to pixels, based on density scale
        return (int) (pixels * scale + 0.5f);
    }
}

 class ExpAdapter extends BaseExpandableListAdapter {

    private Context myContext;
    ExpandableListView _list;

    public ExpAdapter(Context context,ExpandableListView list) {
        myContext = context;
        _list=list;
    }

    public Object getChild(int groupPosition, int childPosition) {
        return null;
    }

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

    public View getChildView(int groupPosition, int childPosition,
            boolean isLastChild, View convertView, ViewGroup parent) {
       
        if (convertView == null) {
            System.out.println("---getChildView --convertView == null");
            LayoutInflater inflater = (LayoutInflater) myContext
                    .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            convertView = inflater.inflate(R.layout.child_row, null);
        }

        TextView tvPlayerName = (TextView) convertView
                .findViewById(R.id.tvPlayerName);
        tvPlayerName
                .setText(ExpandableListViewActivityActivity.arrChildelements[groupPosition][childPosition]);

        return convertView;
    }

    public int getChildrenCount(int groupPosition) {
        return ExpandableListViewActivityActivity.arrChildelements[groupPosition].length;
    }

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

    public int getGroupCount() {
        return ExpandableListViewActivityActivity.arrGroupelements.length;
    }

    public long getGroupId(int groupPosition) {
        return 0;
    }   
   
    // Return a group view. You can load your custom layout here.
    @Override
    public View getGroupView(int groupPosition, boolean isExpanded, View convertView,
            ViewGroup parent) {
        System.out.println("---getGroupView --");
        String group = (String) getGroup(groupPosition);
        if (convertView == null) {
            LayoutInflater infalInflater = (LayoutInflater) myContext
                    .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            convertView = infalInflater.inflate(R.layout.group_row, null);
        }     
       
        //TextView tv = (TextView) convertView.findViewById(R.id.tvGroup);
       // tv.setText(group);
        TextView tvGroupName= (TextView) convertView.findViewById(R.id.tvGroupName);
        TextView tvGroupName2= (TextView) convertView.findViewById(R.id.tvGroupName2);
        TextView textViewPhone= (TextView) convertView.findViewById(R.id.textViewPhone);
        Button addCasePersonAddressBtn= (Button) convertView.findViewById(R.id.addCasePersonAddressBtn);
        Button casePersonEdtBtn= (Button) convertView.findViewById(R.id.casePersonEdtBtn);
        _list.expandGroup(groupPosition);  //used to Expand the child list automatically at the time of displaying
        return convertView;
    }

    public boolean hasStableIds() {
        return false;
    }

    public boolean isChildSelectable(int groupPosition, int childPosition) {
        return true;
    }
}


group_row.xml :-
<?xml version="1.0" encoding="utf-8"?>
<!-- <LinearLayout android:id="@+id/LinearLayout01"
        android:layout_width="fill_parent" android:layout_height="45dip"
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:background="#FAF7F7"
        >
        <ImageView android:id="@+id/ImageView01" android:src="@drawable/ic_launcher"
                android:layout_height="40dip" android:layout_width="40dip" android:layout_marginLeft="40dip"></ImageView>

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

        <TextView android:id="@+id/tvGroup" android:layout_width="fill_parent"
                android:layout_height="wrap_content" android:text="Groups"              
                android:textColor="#000000"
                android:textSize="17dip"></TextView>
</LinearLayout> -->

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical"
    android:paddingLeft="10dip"
     android:background="#FAF7F7"  >

    <TextView android:id="@+id/tvGroupName"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="John Smith"
        android:textSize="18dip"/>
    <TextView android:id="@+id/tvGroupName2"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="23 Years old"
        android:textSize="18dip" />

    <TextView
        android:id="@+id/textViewPhone"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="phone:9292304336"
        android:textSize="18dip" />

     <LinearLayout android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_below="@+id/textViewPhone"
                android:orientation="horizontal"
                android:layout_marginRight="30dip"
                android:layout_marginBottom="10dip" 
                android:gravity="right">
             <Button
            android:id="@+id/addCasePersonAddressBtn"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"      
            android:layout_marginRight="5dip"
           android:text="Edit"
             android:layout_gravity="center_vertical"            
            android:textSize="18dip" />  
            <Button
            android:id="@+id/casePersonEdtBtn"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Add address"
            android:layout_marginLeft="10dip"     
            android:visibility="visible"
            android:layout_gravity="center_vertical"
           />
       
        </LinearLayout>

</LinearLayout>


<!-- <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:paddingBottom="5dip"       
        android:paddingTop="5dip"
    android:background="#FAF7F7"  >
  

       <RelativeLayout android:id="@+id/casePersonLinearLayout"
                   android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_marginBottom="10dip"
                         
                >
               
          
        <RelativeLayout android:id="@+id/casePersonManImageLayout"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="10dip"
        android:layout_marginBottom="10dip"
         >  
        <ImageView
                android:id="@+id/casePersonManImage"
                android:layout_width="16dip"
                android:layout_height="16dip"                                                
                android:layout_marginLeft="10dip"               
                android:scaleType="fitXY"
                android:src="@drawable/ic_launcher"               
               />
        <TextView
            android:id="@+id/casePersonFrstLastNameTxtViw"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerVertical="true"
            android:layout_marginLeft="10dip"
            android:layout_marginRight="10dip"           
            android:layout_toRightOf="@+id/casePersonManImage"
            android:text="John Smith"
            android:textColor="#000000"
            android:textSize="15dip"
            android:textStyle="bold" />
        </RelativeLayout>
       

        <RelativeLayout android:id="@+id/casePersonRelationshipLayout"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"       
        android:layout_marginBottom="10dip"
        android:layout_below="@+id/casePersonManImageLayout"
         >
        <ImageView
                android:id="@+id/casePersonRelationshipImage"
                android:layout_width="16dip"
                android:layout_height="16dip"                                                
                android:layout_marginLeft="10dip"               
                android:scaleType="fitXY"
                android:src="@drawable/ic_launcher"               
               />
        <TextView
            android:id="@+id/relationshipTxtView"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="10dip"           
            android:layout_marginRight="10dip"          
            android:layout_toRightOf="@+id/casePersonRelationshipImage"           
            android:text="23 years old"
            android:textSize="13dip"
            android:textColor="#000000" />
        </RelativeLayout>
       
       

        <TextView
            android:id="@+id/DOBTxtView"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="10dip"
            android:layout_below="@+id/casePersonRelationshipLayout"
            android:text=" phnone-9292304336"
            android:layout_marginBottom="10dip" 
            android:textColor="#000000"
            android:textSize="13dip" />
       
       

       <TextView
            android:id="@+id/mobilePhTxtView"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"           
            android:layout_below="@+id/DOBTxtView"
            android:layout_marginLeft="10dip"
            android:text="phone-9292929922"
            android:textColor="#000000"
            android:textSize="12dip" />
       
        </RelativeLayout>
       
       
       <LinearLayout android:id="@+id/linearGroupLayout"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_below="@+id/casePersonLinearLayout"
                android:orientation="horizontal"
                android:layout_marginRight="30dip"
                android:layout_marginBottom="10dip" 
                android:gravity="right">
             <Button
            android:id="@+id/addCasePersonAddressBtn"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"      
            android:layout_marginRight="5dip"
            android:text="Edit"
             android:layout_gravity="center_vertical"            
            android:textSize="18dip" />  
            <Button
            android:id="@+id/casePersonEdtBtn"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"            
            android:layout_marginLeft="10dip" 
            android:text="Add Address"    
            android:layout_gravity="center_vertical"
           />
       
        </LinearLayout>      

</RelativeLayout> -->


child_row.xml :-
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical"
     android:background="#FAF7F7"
      >
<RelativeLayout android:id="@+id/casePersonLinearLayout"
                   android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_marginBottom="10dip"
                android:layout_marginLeft="60dip"            
                >
    <TextView android:id="@+id/tvPlayerName"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:textColor="#00FFFF"
        android:text="player" />
    <TextView
    android:id="@+id/textViewAddres1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Address1"
    android:layout_below="@+id/tvPlayerName"
    android:textColor="#00FFFF" />
    <TextView
    android:id="@+id/textViewAddres2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Address2"
    android:layout_below="@+id/textViewAddres1"
    android:textColor="#00FFFF" />
    <TextView
    android:id="@+id/textViewPhnonee"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="ph:9292304336"
    android:layout_below="@+id/textViewAddres2"
    android:textColor="#00FFFF" />

    <Button
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBottom="@+id/textViewPhnonee"
        android:layout_alignParentRight="true"
        android:layout_marginRight="33dp"
        android:text="Edit" />

    </RelativeLayout>



</LinearLayout>



main.xml :-
<?xml version="1.0" encoding="UTF-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical"
    android:background="#FAF7F7" >

    <ExpandableListView
        android:id="@+id/expandableListView1"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:groupIndicator="@drawable/ic_launcher" >
    </ExpandableListView>
    <TextView
            android:id="@+id/android:empty"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:text="No Items" >
    </TextView>
</LinearLayout>

///i implemented this in my LegelPlex Project of Case_PersonScreen.java file..

Comments

  1. I have to develop a 3 level expandable listview using a json array . Please help me

    ReplyDelete
  2. Hi Tilak,

    Thanks a lot for this post and you saved my day.
    It was really helpful for me.

    Really thank you thank you very much.

    ReplyDelete

Post a Comment