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

Updated code of expandable list rows,that 1)Hide/Show the "More" button based on text length(i.e Hide more button if text length lessthan two rows). 2)disable row click functionality if row having text lessthan 2-rows. 3)using only single .xml file(i.e row.xml) instead of two(i.e row.xml,expand_row.xml files) i implemented this in LegelPlex Project..

ExpandablListrowsimplification.java : -

package org.dharani.ExpandableListRow;

import org.dharani.ExpandableListRow.ExpandablListrowsimplification.AttornyAsignmntArrayAdapter.ViewHolder;

import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.util.Log;
import android.view.Display;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.BaseAdapter;
import android.widget.ListView;
import android.widget.TextView;

public class ExpandablListrowsimplification extends Activity {
   
    //code for expandable list rows..
    ListView listView;
    AttornyAsignmntArrayAdapter objAdapter;
    String attornyAsignmntArryList[]={"****pavan tilak *******pavan tilak pavan******tilak pavantilak*****pavntilak*******tilak pavantilak",
            "----pavan tilak--------pavan tilak pavan-------tilak pavantilak-----pavntilak----tilak pavantilak"
            ,"&&&&&pavan tilak&&&&&&&&&&pavan tilak pavan &&&&&&& tilak pavantilak &&&&&& pavntilak &&&&&& tilak pavantilak",
            "$$$$$pavan tilak$$$$$$$$$pavan tilak pavan $$$$$$$$ tilak pavantilak$$$$$$$$$ pavntilak$$$$$$$$4 tilak pavantilak"
            ,"%%%%% jhkdhs khasj khjhksah %%% dfsf %%%%%% jhkdhs khasj khjhksah %%% dfsf %"
            ,"===== jhkdhs khasj khjhksah ==== dfsf ==== jhkdhs khasj "
            ,"===== jhkdhs khasj khjhksah ==== dfsf===== jhkdhs khasj khjhksah ==== dfsf"
            ,"PavanTilakPavanTilakPavanTilakPavanTilakPavanTilakPavanTilakPavanTilakPavanT"//76
            ,"PavanTilakPavanTilakPavanTilakPavanTil"//38
            ,"PavanTilakPavanTilak"};//20
    ViewHolder holder = null;
    boolean flag=false;
    int clickedItemPosition;
    int moreTextFlag[];///this array will be used for to observing the text(i.e More/Less) in TextView of each row..
    int countFlag=0;
    int moreLessArray[];
    int i=0;
   
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);       
       
        listView = (ListView) findViewById(R.id.list);
        listView.setOnItemClickListener(new OnItemClickListener() {
            public void onItemClick(AdapterView<?> adapter, View view, int position, long id) {
               
                //moreTextFlag=0 --> moreTextView having text->'Less'  && moreTextFlag=1 --> moreTextView having text->'More'                   
                System.out.println("******** More buttonClicked Position"+position);
                System.out.println("---flag value in button click ----"+flag);                               
               
               
                //String moreText=holder.memoMoreBtnExpand.getText().toString();
                //System.out.println("---Text on more buton in button click & length----"+moreText+" "+moreText.length());
               
                if(/*moreText.equals("More")*/moreTextFlag[position]==1){
                   
                    System.out.println("******** moreText.equals (More)");
                   
                    if(flag){  //this block is mainly used to handle when clicking the More button on one row,and immediatly clicking More button on other row..
                       
                        //below two lines used for compressing the already expanded lines..
                        flag=!flag; //flag-false                           
                        listView.setAdapter(objAdapter);
                       
                        //below lines used for expanding the row
                        flag=!flag; //flag=true if the user clicks the more button..
                        holder.memoMoreBtnExpand.setText("Less");
                        moreTextFlag[position]=0;//reprasents this row having text of 'Less'
                        clickedItemPosition=position;
                        listView.setAdapter(objAdapter);                           
                       
                    }else{
                    flag=!flag; //flag=true if the user clicks the more button...
                    System.out.println("*****flag in else flag *****"+flag);
                    holder.memoMoreBtnExpand.setText("Less");
                    moreTextFlag[position]=0;//reprasents this row having text of 'Less'
                    clickedItemPosition=position;
                    listView.setAdapter(objAdapter);
                    System.out.println("******** More Text");
                    //holder.textViewmobilName.setText(attornyAsignmntArryList[position]);
                    //holder.memoMoreBtnExpand.setText("Less");
                }                                   
                   
                }else{                                   
                    System.out.println("******** moreText.equals (Less)");
                    flag=!flag; //flag-false
                    System.out.println("---flag in else ----"+flag);
                    holder.memoMoreBtnExpand.setText("More");
                    clickedItemPosition=position;
                    moreTextFlag[position]=1;//reprasents this row having text of 'More'
                    listView.setAdapter(objAdapter);                       
                }                               
                listView.setSelection(position);  //used for displaying the selected row...
               
            }
        });
       
       
        moreTextFlag=new int[attornyAsignmntArryList.length];
        moreLessArray=new int[attornyAsignmntArryList.length];
       
        objAdapter=new AttornyAsignmntArrayAdapter(this);
        listView.setAdapter(objAdapter);
    }
   
    class AttornyAsignmntArrayAdapter extends BaseAdapter
    {

        @Override
        public int getCount() {
            // TODO Auto-generated method stub
            return attornyAsignmntArryList.length;
        }

        Activity context;

        public AttornyAsignmntArrayAdapter(Activity context) {
            super();
           
            Log.d("hh","sgbdfjfdgfk");
           
            this.context = context;
        }

         class ViewHolder {
           
           
             TextView textViewmobilName,memoTextTxtViwExpand;               
             TextView memoMoreBtnExpand,memoEditBtnExpand;
            }

        public View getView(final int position, View convertView, ViewGroup parent){//here we inflating the layout "R.layout.cars_row"
            //ViewHolder holder = null;
            View rowView = convertView;           
           
           
            if (rowView == null) {
               
                LayoutInflater inflater = context.getLayoutInflater();
           
                rowView = inflater.inflate(R.layout.attorny_assignment_row, null, true);

                holder = new ViewHolder();

                holder.textViewmobilName=(TextView) rowView.findViewById(R.id.textViewmobilName);
                holder.memoTextTxtViwExpand=(TextView) rowView.findViewById(R.id.memoTextTxtViwExpand);       
                holder.memoMoreBtnExpand=(TextView) rowView.findViewById(R.id.memoMoreBtnExpand);       
                holder.memoEditBtnExpand=(TextView) rowView.findViewById(R.id.memoEditBtnExpand);                           
                rowView.setTag(holder);           
               
            }
            else
            {
                holder = (ViewHolder) rowView.getTag();
            }
            i++;                   
           
            String reviewernotesstring=attornyAsignmntArryList[position];
            System.out.println("***** reviewernotesstring-->"+reviewernotesstring);
            System.out.println("***** reviewernotesstring length-->"+reviewernotesstring.length());        
           
           
           
            //code to devide the string into different n.of lines..
            Display display = ((WindowManager) getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
            int screenWidth = display.getWidth();
            System.out.println("***** screenWidthwid-->"+screenWidth);
            // 'screenWidth/8' wil return the number of characters one row will have
            int numbrOfRowsPossible=(screenWidth-10)/8; ///each caharacter having 8-pixels
            System.out.println("***** numbrOfRowsPossible-->"+numbrOfRowsPossible);         
               
           
            //this code used to maintain Array of rows having  More-1 / Less-0 values
            if(countFlag==0){//its a first time thing..means this part executed only frst time
                System.out.println(" ,,,,,,,,,,,countFlag,,,,,,,,,,"+countFlag);
                if(attornyAsignmntArryList[position].length()<= (numbrOfRowsPossible*2)){
                    moreLessArray[position]=0;//its having Less Button
                    holder.memoMoreBtnExpand.setVisibility(View.GONE);
                }
                else
                    moreLessArray[position]=1;//its having More Button             
            }
            else
            {
                System.out.println(" ,,,,,,,,,,,countFlag,,,,,,,,,,"+countFlag);
               
                if(moreLessArray[position]==0)
                    holder.memoMoreBtnExpand.setVisibility(View.GONE);
                else
                    holder.memoMoreBtnExpand.setVisibility(View.VISIBLE);                   
            }
           
            if(i==attornyAsignmntArryList.length){
                countFlag++; //disable 'countFlag' to execute above block on second time of calling the adapter..
                for(int i=0;i<moreLessArray.length;i++)
                    System.out.println(".......moreLessArray->"+i+"="+moreLessArray[i]);
                   
            }
           
            String tempString ="";   
            if(reviewernotesstring.length()>numbrOfRowsPossible){    //means user entered string will farm more than one row..
               
            int count=1;
            int nbLines = 1;
            int start=0,end;
            end=numbrOfRowsPossible;
            for(int i=1;i<=reviewernotesstring.length();i++)
            {           
                 if(count==numbrOfRowsPossible && numbrOfRowsPossible<reviewernotesstring.length()){
                     if(end>reviewernotesstring.length()){
                            tempString=tempString+reviewernotesstring.substring(start, reviewernotesstring.length())+"\n";
                            nbLines++;
                     } else{
                            tempString=tempString+reviewernotesstring.substring(start, end)+"\n";
                            nbLines++;
                     }
                   
                    System.out.println(" %%%%% tempString %%"+tempString);
                    System.out.println(" %%%%% tempString length %%"+tempString.length());
                   
                    start=end;//for getting substring of next line,with start and end elements..
                    end=start+numbrOfRowsPossible;
                   
                    count=1;
                   
                }
                count++;
            } //for loop            
            System.out.println("***** lines-->"+nbLines);
            System.out.println("***** start-->"+start);
            System.out.println("***** end-->"+end);
            System.out.println("***** count-->"+count);
            System.out.println("***** tempString-->"+tempString);
            System.out.println("***** tempString len-->"+tempString.length());
            System.out.println("***** reviewernotesstring len-->"+reviewernotesstring.length());
            System.out.println("***** attornyAsignmntArryList-->"+attornyAsignmntArryList[position]);
            System.out.println("***** attornyAsignmntArryList len-->"+attornyAsignmntArryList[position].length());
           
           
            int coefficient=tempString.length()/numbrOfRowsPossible;//because tempString having more length after adding '\n' to it..here we get how many '\n' values added to 'tempString'
           
            if((tempString.length()-coefficient)<reviewernotesstring.length())//means if user enters only '2*numbrOfRowsPossible' chars
                tempString=tempString+reviewernotesstring.substring(start, reviewernotesstring.length());//adding remaiming string(half part of String) after adding complete rows
            }
                   
           
           if(flag && clickedItemPosition==position /*&&     holder.textViewmobilName.getText().toString().equals("More")*/){              
               System.out.println("########### flag && clickedItemPosition==position ");
               holder.memoMoreBtnExpand.setText("Less");
               moreTextFlag[position]=0;//reprasents this row having text of 'Less'
               holder.memoTextTxtViwExpand.setText(tempString/*attornyAsignmntArryList[position]*/);     //display all chars                  
                  
           }else{              
            System.out.println("########### else part ");            
            if(reviewernotesstring.length()<=(2*numbrOfRowsPossible)){
               
                if(reviewernotesstring.length()<=numbrOfRowsPossible){//block used for display string having only one row..
                    rowView.setFocusable(true); rowView.setClickable(true); //code to disable the row click...
                    holder.memoTextTxtViwExpand.setText(reviewernotesstring);   
                    holder.memoMoreBtnExpand.setText("Less");               
                    moreTextFlag[position]=0;//reprasents this row having text of 'Less'               
            }else{
                holder.memoTextTxtViwExpand.setText(tempString);     //display all chars if formated string having two rows exactly..
                rowView.setFocusable(true); rowView.setClickable(true); //code to disable the row click...
                holder.memoMoreBtnExpand.setText("Less");               
                moreTextFlag[position]=0;//reprasents this row having text of 'Less'
                }
            } else{
                holder.memoTextTxtViwExpand.setText(tempString.substring(0, 2*numbrOfRowsPossible+1));//display only two rows(lines) if lineCount > 2
                holder.memoMoreBtnExpand.setText("More");
                rowView.setFocusable(false); rowView.setClickable(false); //code to disable the row click...
                moreTextFlag[position]=1;//reprasents this row having text of 'More'
            }
        }//if-flag  
           
           
           
           
           
            holder.memoEditBtnExpand.setOnClickListener(new OnClickListener() {               
                @Override
                public void onClick(View v) {
                    // TODO Auto-generated method stub
                    System.out.println("******** Edit buttonClicked Position"+position);
                   
                    /*//Invoke UpdateAttorneyAssignments screen...
                    Intent i=new Intent(AttornyAssignmentScreen.this,UpdateAttorneyAssignmentsScreen.class);   
                    Bundle b=new Bundle();
                    System.out.println("attornyAsignmntArryList.get(position)*****************case person screen "+attornyAsignmntArryList.get(position));
                    b.putParcelable("objclsAttorneyAssignment",attornyAsignmntArryList.get(position));
                   
                    i.putExtras(b);
                    startActivityForResult(i,10);*/
                }
            });
            holder.memoMoreBtnExpand.setOnClickListener(new OnClickListener() {               
                @Override
                public void onClick(View v) {
                   

                    //moreTextFlag=0 --> moreTextView having text->'Less'  && moreTextFlag=1 --> moreTextView having text->'More'                   
                    System.out.println("******** More buttonClicked Position"+position);
                    System.out.println("---flag value in button click ----"+flag);                               
                   
                   
                    //String moreText=holder.memoMoreBtnExpand.getText().toString();
                    //System.out.println("---Text on more buton in button click & length----"+moreText+" "+moreText.length());
                   
                    if(/*moreText.equals("More")*/moreTextFlag[position]==1){
                       
                        System.out.println("******** moreText.equals (More)");
                       
                        if(flag){  //this block is mainly used to handle when clicking the More button on one row,and immediatly clicking More button on other row..
                           
                            //below two lines used for compressing the already expanded lines..
                            flag=!flag; //flag-false                           
                            listView.setAdapter(objAdapter);
                           
                            //below lines used for expanding the row
                            flag=!flag; //flag=true if the user clicks the more button..
                            holder.memoMoreBtnExpand.setText("Less");
                            moreTextFlag[position]=0;//reprasents this row having text of 'Less'
                            clickedItemPosition=position;
                            listView.setAdapter(objAdapter);                           
                           
                        }else{
                        flag=!flag; //flag=true if the user clicks the more button...
                        System.out.println("*****flag in else flag *****"+flag);
                        holder.memoMoreBtnExpand.setText("Less");
                        moreTextFlag[position]=0;//reprasents this row having text of 'Less'
                        clickedItemPosition=position;
                        listView.setAdapter(objAdapter);
                        System.out.println("******** More Text");
                        //holder.textViewmobilName.setText(attornyAsignmntArryList[position]);
                        //holder.memoMoreBtnExpand.setText("Less");
                    }                                   
                       
                    }else{                                   
                        System.out.println("******** moreText.equals (Less)");
                        flag=!flag; //flag-false
                        System.out.println("---flag in else ----"+flag);
                        holder.memoMoreBtnExpand.setText("More");
                        clickedItemPosition=position;
                        moreTextFlag[position]=1;//reprasents this row having text of 'More'
                        listView.setAdapter(objAdapter);                       
                    }                               
                    listView.setSelection(position);  //used for displaying the selected row...
                   
                    }                   
               
                   
                    /*//Invoke UpdateAttorneyAssignments screen...
                    Intent i=new Intent(AttornyAssignmentScreen.this,UpdateAttorneyAssignmentsScreen.class);   
                    Bundle b=new Bundle();
                    System.out.println("attornyAsignmntArryList.get(position)*****************case person screen "+attornyAsignmntArryList.get(position));
                    b.putParcelable("objclsAttorneyAssignment",attornyAsignmntArryList.get(position));
                   
                    i.putExtras(b);
                    startActivityForResult(i,10);*/
               
            });
           
            return rowView;

        }

        @Override
        public long getItemId(int position) {
            // TODO Auto-generated method stub
            return position; 
        }

        @Override
        public Object getItem(int position) {
            // TODO Auto-generated method stub
            return position;
        }


    }
   
}

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" >

    <TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="@string/hello" />
     <ListView
        android:id="@+id/list"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:focusableInTouchMode="false"
        />
</LinearLayout>

attorny_assignment_row.xml : -

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

    <RelativeLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:paddingTop="5dip"
        android:paddingBottom="5dip" >

    <TextView
        android:id="@+id/textViewmobilName"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"       
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"                 
        android:layout_marginLeft="10dip"
        android:layout_marginRight="10dip"      
        android:text="Suresh Mobile added by Upendra on 22/06/2012 88:45 pm" />
       

    <!-- <TextView
        android:id="@+id/addedByAttornyAsignmntTxtView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/displayAttornyAsignmntTxtView"
        android:layout_below="@+id/displayAttornyAsignmntTxtView"
        android:layout_marginTop="21dp"
        android:text="Added By" /> -->

    <TextView
            android:id="@+id/memoTextTxtViwExpand"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignLeft="@+id/textViewmobilName"
            android:layout_below="@+id/textViewmobilName"          
            android:text="wsrqwerqe" />
   
   
    <TextView
        android:id="@+id/memoMoreBtnExpand"
        android:layout_width="60dip"
        android:layout_height="40dip"
        android:layout_below="@+id/memoTextTxtViwExpand"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="15dp"            
        android:text="More"      
        android:gravity="center"
        android:onClick="MoreButtonClick"       
         />

    <TextView
        android:id="@+id/memoEditBtnExpand"
        android:layout_width="60dip"
        android:layout_height="40dip"
        android:layout_alignParentRight="true"
        android:layout_below="@+id/memoTextTxtViwExpand"
        android:layout_marginTop="15dip"
        android:layout_marginRight="30dp"       
        android:gravity="center"
        android:text="Edit"
         />
    
    </RelativeLayout>

    </RelativeLayout>


Comments