1. Download our Official Android App: Forums for Android!

Apps Cache Memory and Expandable Listview Issue

Discussion in 'Android Development' started by Ananya Chatterjee, Aug 12, 2016.

  1. Ananya Chatterjee

    Thread Starter
    Rank:
    None
    Points:
    15
    Posts:
    1
    Joined:
    Aug 11, 2016

    Aug 11, 2016
    1
    0
    15
    Female
    I am new to android and I need some guidance.
    I have two issues in my app - a) While using the application if I remove the app from the cache the data is not visible any more. We have to log out and again login to the app to get the data. I think there is an issue in SharedPreferenceClass.

    b)In "Pending Approval" tag in "To Do List" I want to add an Expandable Listview. Though I have already added the listview. But nothing is going to visible in my activity. It will look like the picture below
    [​IMG]


    a)Cache Memory Issue:

    Code (Text):
    1. public class SharedPreferencesClass {
    2.  
    3.  
    4.     private SharedPreferences sp;
    5.  
    6.     public boolean read(Context context)
    7.     {
    8.         Boolean value;
    9.         sp = context.getSharedPreferences("MyPref", 0);
    10.         value=sp.getBoolean("MyPref", false);
    11.         return value;
    12.     }
    13.     public void write(Context context,Boolean val)
    14.     {
    15.         sp=context.getSharedPreferences("MyPref",0);
    16.         SharedPreferences.Editor editor=sp.edit();
    17.         editor.clear();
    18.         editor.putBoolean("MyPref",val);
    19.         editor.commit();
    20.     }
    21.     public void clear(Context context)
    22.     {
    23.         sp=context.getSharedPreferences("MyPref",0);
    24.         SharedPreferences.Editor editor=sp.edit();
    25.         editor.clear();
    26.         editor.commit();
    27.     }
    28. }
    Logout:

    Code (Text):
    1. new SharedPreferencesClass().clear(ToDoListActivity.this);
    2. Intent i=new Intent(ToDoListActivity.this,LoginActivity.class);
    3. startActivity(i);
    4. finish();
    Login:

    Code (Text):
    1. new SharedPreferencesClass().write(LoginActivity.this,true);

    b)Expandable List View

    pending_expandable_heading.xml

    Code (Text):
    1. <LinearLayout
    2.     xmlns:android="http://schemas.android.com/apk/res/android"
    3.     android:orientation="vertical"
    4.     android:layout_width="match_parent"
    5.     android:layout_height="match_parent">
    6.  
    7.     <TextView
    8.         android:id="@+id/lblListHeader"
    9.         android:layout_width="fill_parent"
    10.         android:layout_height="wrap_content"
    11.         android:paddingLeft="?android:attr/expandableListPreferredItemPaddingLeft"
    12.         android:textSize="20dp"
    13.         android:text="Heading"
    14.         android:layout_margin="10dp"/>
    15.  
    16. </LinearLayout>
    pending_expandable_listview.xml

    Code (Text):
    1. <android.support.v4.widget.SwipeRefreshLayout android:id="@+id/swipeRefreshLayout"
    2.     android:layout_width="match_parent"
    3.     android:layout_height="match_parent"
    4.  
    5.     xmlns:android="http://schemas.android.com/apk/res/android">
    6.     <ExpandableListView
    7.         android:id="@+id/lvExp"
    8.         android:layout_height="match_parent"
    9.         android:layout_width="match_parent"/>
    10. </android.support.v4.widget.SwipeRefreshLayout>


    activity_lead_details.xml

    Code (Text):
    1. <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    2.     android:layout_width="match_parent"
    3.     android:layout_height="match_parent">
    4.     <android.support.v7.widget.CardView
    5.         xmlns:card_view="http://schemas.android.com/apk/res-auto"
    6.         xmlns:android="http://schemas.android.com/apk/res/android"
    7.         android:id="@+id/card_view"
    8.         android:layout_width="match_parent"
    9.         android:layout_height="wrap_content"
    10.  
    11.         card_view:cardUseCompatPadding="true"
    12.         card_view:cardElevation="5dp"
    13.         card_view:cardCornerRadius="15dp">
    14.  
    15.         <LinearLayout
    16.             android:id="@+id/layout_details"
    17.             android:layout_width="match_parent"
    18.             android:orientation="vertical"
    19.             android:padding="15dp"
    20.             android:layout_height="wrap_content">
    21.  
    22.             <RelativeLayout
    23.                 android:layout_width="wrap_content"
    24.                 android:layout_height="wrap_content">
    25.  
    26.                 <TextView
    27.                     android:id="@+id/txt_date"
    28.                     android:layout_width="wrap_content"
    29.                     android:layout_height="wrap_content"
    30.                     android:text="Date"
    31.                     android:textSize="16sp"
    32.                     android:padding="5dp"/>
    33.  
    34.                 <TextView
    35.                     android:id="@+id/txt_loc"
    36.                     android:layout_width="wrap_content"
    37.                     android:layout_height="wrap_content"
    38.                     android:text="Location"
    39.                     android:textSize="16sp"
    40.                     android:padding="5dp"
    41.                     android:layout_toRightOf="@+id/txt_date"
    42.                     android:layout_marginLeft="10dp"/>
    43.             </RelativeLayout>
    44.  
    45.             <RelativeLayout
    46.                 android:layout_width="match_parent"
    47.                 android:layout_height="wrap_content">
    48.                 <Button
    49.                     android:id="@+id/noteBtn"
    50.                     android:layout_height="40dp"
    51.                     android:layout_width="40dp"
    52.                     android:padding="10dp"
    53.                     android:layout_alignParentTop="true"
    54.                     android:layout_alignParentRight="true"
    55.                     android:onClick="clickNote"
    56.                     android:background="@drawable/note"/>
    57.                 <TextView
    58.                     android:layout_toLeftOf="@+id/noteBtn"
    59.                     android:id="@+id/txtOne"
    60.                     android:layout_width="match_parent"
    61.                     android:layout_height="wrap_content"
    62.                     android:textSize="20sp"
    63.                     android:text="Home"
    64.                     android:padding="5dp"/>
    65.             </RelativeLayout>
    66.             <RelativeLayout
    67.                 android:layout_width="wrap_content"
    68.                 android:layout_height="wrap_content">
    69.  
    70.                 <Button
    71.                     android:id="@+id/call_btn"
    72.                     android:layout_width="20dp"
    73.                     android:layout_height="20dp"
    74.                     android:background="@drawable/call"
    75.                     android:layout_marginLeft="10dp"
    76.                     android:layout_marginTop="5dp"/>
    77.                 <TextView
    78.                     android:id="@+id/txt_contact"
    79.                     android:layout_width="match_parent"
    80.                     android:layout_height="wrap_content"
    81.                     android:layout_toRightOf="@+id/call_btn"
    82.                     android:textSize="16sp"
    83.                     android:text="Contact"
    84.                     android:padding="5dp"
    85.                     android:layout_marginLeft="10dp"
    86.                     android:background="@android:color/transparent"/>
    87.  
    88.             </RelativeLayout>
    89.  
    90.             <RelativeLayout
    91.                 android:layout_width="wrap_content"
    92.                 android:layout_height="wrap_content">
    93.  
    94.                 <Button
    95.                     android:id="@+id/mail_btn"
    96.                     android:layout_width="20dp"
    97.                     android:layout_height="20dp"
    98.                     android:background="@drawable/mail"
    99.                     android:layout_marginLeft="10dp"
    100.                     android:layout_marginTop="5dp"/>
    101.                 <TextView
    102.                     android:id="@+id/txt_mail"
    103.                     android:layout_width="match_parent"
    104.                     android:layout_height="wrap_content"
    105.                     android:layout_toRightOf="@+id/mail_btn"
    106.                     android:textSize="16sp"
    107.                     android:text="Mail"
    108.                     android:padding="5dp"
    109.                     android:layout_marginLeft="10dp"
    110.                     android:background="@android:color/transparent"/>
    111.             </RelativeLayout>
    112.  
    113.             <TextView
    114.                 android:id="@+id/txtTwo"
    115.                 android:layout_width="match_parent"
    116.                 android:layout_height="wrap_content"
    117.                 android:textSize="16sp"
    118.                 android:text="Home"
    119.                 android:padding="5dp"/>
    120.  
    121.             <TextView
    122.                 android:id="@+id/txtThree"
    123.                 android:layout_width="match_parent"
    124.                 android:layout_height="wrap_content"
    125.                 android:textSize="16sp"
    126.                 android:text="Home"
    127.                 android:padding="5dp"/>
    128.  
    129.             <TextView
    130.                 android:id="@+id/txtFour"
    131.                 android:layout_width="match_parent"
    132.                 android:layout_height="wrap_content"
    133.                 android:textSize="16sp"
    134.                 android:text="Home"
    135.                 android:padding="5dp"/>
    136.             <TextView
    137.                 android:id="@+id/txtFive"
    138.                 android:layout_width="match_parent"
    139.                 android:layout_height="wrap_content"
    140.                 android:textSize="16sp"
    141.                 android:text="Home"
    142.                 android:padding="5dp"/>
    143.             <TextView
    144.                 android:id="@+id/txtSix"
    145.                 android:layout_width="match_parent"
    146.                 android:layout_height="wrap_content"
    147.                 android:textSize="16sp"
    148.                 android:text="Home"
    149.                 android:padding="5dp"/>
    150.         </LinearLayout>
    151.  
    152.     </android.support.v7.widget.CardView>
    153.     <RelativeLayout
    154.         android:padding="20dp"
    155.         android:layout_below="@+id/card_view"
    156.         android:layout_width="match_parent"
    157.         android:layout_height="wrap_content">
    158.     <Button
    159.         android:id="@+id/continueBtn"
    160.         android:text="@string/continue_btn"
    161.         android:padding="10dp"
    162.         android:layout_alignParentLeft="true"
    163.         android:layout_centerVertical="true"
    164.         android:layout_width="100dp"
    165.         android:textColor="#fff"
    166.         android:background="@drawable/lft"
    167.         android:textStyle="bold"
    168.         android:textSize="12sp"
    169.         android:onClick="clickContinue"
    170.         android:layout_height="50dp" />
    171.  
    172.     <Button
    173.         android:id="@+id/yesBtn"
    174.         android:text="@string/yes_btn"
    175.         android:padding="10dp"
    176.         android:layout_alignParentRight="true"
    177.         android:layout_centerVertical="true"
    178.         android:layout_width="100dp"
    179.         android:textColor="#fff"
    180.         android:background="@drawable/rit"
    181.         android:textStyle="bold"
    182.         android:textSize="12sp"
    183.         android:onClick="clickYes"
    184.         android:layout_height="50dp" />
    185.     <Button
    186.         android:id="@+id/reassignBtn"
    187.         android:text="@string/reassign_btn"
    188.         android:padding="10dp"
    189.         android:layout_centerHorizontal="true"
    190.         android:layout_centerVertical="true"
    191.         android:layout_width="100dp"
    192.         android:textColor="#fff"
    193.         android:background="@drawable/mid"
    194.         android:textStyle="bold"
    195.         android:textSize="12sp"
    196.         android:onClick="clickReassign"
    197.         android:layout_height="50dp" />
    198.  
    199. </RelativeLayout>
    200. </RelativeLayout>
    201.  
    ExpandableListAdapter.java:

    Code (Text):
    1. public class ExpandableListAdapter extends BaseExpandableListAdapter implements NetworkCallback {
    2.  
    3. private HashMap<String, List<LeadBO>> _listDataChild;
    4. private List<PendingBO> itemList;
    5. private Context context;
    6. private ViewHolderItem viewHolder = null;
    7. private ViewHolderItem viewHolder1 = null;
    8.  
    9. public  String empName = "";
    10. public String empId = "";
    11. List<EmpolyeBO> memberList;
    12.  
    13. public ExpandableListAdapter(Context context, List<PendingBO> itemList,
    14.                              HashMap<String, List<LeadBO>> listChildData) {
    15.     this.context = context;
    16.     this.itemList = itemList;
    17.     this._listDataChild = listChildData;
    18.     callMemberList();
    19. }
    20.  
    21. @Override
    22. public Object getChild(int groupPosition, int childPosititon) {
    23.     return this._listDataChild.get(this.itemList.get(groupPosition)).get(childPosititon);
    24. }
    25.  
    26. @Override
    27. public long getChildId(int groupPosition, int childPosition) {
    28.     return childPosition;
    29. }
    30.  
    31. @Override
    32. public void updateScreen(String data, String tag) {
    33.     if(tag.compareTo(ApiUtil.TAG_MEMBER_LIST)==0){
    34.         memberList = MemberListParsar.parseEmplyoee(data);
    35.     }
    36.     if(tag.compareTo(ApiUtil.TAG_DEAD_LIST_PENDING)==0){
    37.         Utility.ShowLongNotification(context, ErrorUtil.DEAD_LEAD_MESSAGE);
    38.         ((Activity) context).finish();
    39.     }
    40.     if(tag.compareTo(ApiUtil.TAG_ADD_LEAD_EMP)==0){
    41.         Utility.ShowLongNotification(context, ErrorUtil.REASSIGNED_MSG);
    42.         ((Activity) context).finish();
    43.     }
    44. }
    45.  
    46. static class ViewHolderItem {
    47.  
    48.     public TextView txtLoc;
    49.     public TextView txtDate;
    50.     public TextView txtOne;
    51.     public TextView tv_contact;
    52.     public TextView tv_mail;
    53.     public TextView txtTwo;
    54.     public TextView txtThree;
    55.     public TextView txtFour;
    56.     public TextView txtFive;
    57.     public TextView txtSix;
    58.  
    59.     public CardView cardView;
    60.  
    61.     public TextView lblListHeader;
    62. }
    63.  
    64. @Override
    65. public View getChildView(int groupPosition, final int childPosition,
    66.                          boolean isLastChild, View convertView, ViewGroup parent) {
    67.  
    68.     final LeadBO leadBO = (LeadBO) getChild(groupPosition, childPosition);
    69.  
    70.     if (convertView == null) {
    71.         LayoutInflater infalInflater = (LayoutInflater) this.context
    72.                 .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    73.         convertView = infalInflater.inflate(R.layout.activity_lead_details, null);
    74.  
    75.         viewHolder = new ViewHolderItem();
    76.         viewHolder.txtLoc = (TextView) convertView.findViewById(R.id.txt_loc);
    77.         viewHolder.txtDate = (TextView) convertView.findViewById(R.id.txt_date);
    78.         viewHolder.txtOne = (TextView) convertView.findViewById(R.id.txtOne);
    79.         viewHolder.tv_contact = (TextView) convertView.findViewById(R.id.txt_contact);
    80.         viewHolder.tv_mail = (TextView) convertView.findViewById(R.id.txt_mail);
    81.         viewHolder.txtTwo = (TextView) convertView.findViewById(R.id.txtTwo);
    82.         viewHolder.txtThree = (TextView) convertView.findViewById(R.id.txtThree);
    83.         viewHolder.txtFour = (TextView) convertView.findViewById(R.id.txtFour);
    84.         viewHolder.txtFive = (TextView) convertView.findViewById(R.id.txtFive);
    85.         viewHolder.txtSix = (TextView) convertView.findViewById(R.id.txtSix);
    86.         viewHolder.cardView = (CardView) convertView.findViewById(R.id.card_view);
    87.  
    88.         convertView.setTag(viewHolder);
    89.     }else{
    90.         viewHolder = (ViewHolderItem) convertView.getTag();
    91.     }
    92.     decComponent();
    93.     return convertView;
    94. }
    95.  
    96. private void decComponent() {
    97.     PendingBO pendingBO = AppController.getInstance().pendingBO;
    98.  
    99.     LeadBO lead= pendingBO.getLead();
    100.     viewHolder.txtLoc.setText(lead.getLocation());
    101.     viewHolder.txtDate.setText(lead.getDate());
    102.     viewHolder.txtOne.setText(lead.getName());
    103.     viewHolder.tv_contact.setText(lead.getPhNo());
    104.     viewHolder.tv_mail.setText(lead.getEmail());
    105.     viewHolder.txtTwo.setText(lead.getProject()+" : "+lead.getArea());
    106.     viewHolder.txtThree.setText("Budget"+" : "+lead.getBudget());
    107.     viewHolder.txtFour.setText( lead.getSource());
    108.  
    109.     viewHolder.txtFive.setText("Reason :"+pendingBO.getReason());
    110.     viewHolder.txtSix.setText("BDE Name : "+pendingBO.getEmpName());
    111.  
    112.     viewHolder.tv_contact.setPaintFlags(viewHolder.tv_contact.getPaintFlags() |   Paint.UNDERLINE_TEXT_FLAG);
    113.     viewHolder.tv_mail.setPaintFlags(viewHolder.tv_mail.getPaintFlags() | Paint.UNDERLINE_TEXT_FLAG);
    114.  
    115.     viewHolder.tv_contact.setOnClickListener(new View.OnClickListener() {
    116.         @Override
    117.         public void onClick(View v) {
    118.  
    119.             String number = viewHolder.tv_contact.getText().toString().trim();
    120.             Intent callIntent = new Intent(Intent.ACTION_CALL);
    121.             callIntent.setData(Uri.parse("tel:" + number));
    122.             if (ActivityCompat.checkSelfPermission(context, Manifest.permission.CALL_PHONE) != PackageManager.PERMISSION_GRANTED) {
    123.                 return;
    124.             }
    125.             context.startActivity(callIntent);
    126.         }
    127.     });
    128.  
    129.     viewHolder.tv_mail.setOnClickListener(new View.OnClickListener() {
    130.  
    131.         @Override
    132.         public void onClick(View v) {
    133.             String mail=viewHolder.tv_mail.getText().toString().trim();
    134.             Intent i = new Intent(Intent.ACTION_SEND);
    135.             i.setType("message/rfc822");
    136.             //  i.putExtra(Intent.EXTRA_EMAIL, new String[]{String.valueOf(Uri.parse(mail))});
    137.             i.putExtra(Intent.EXTRA_EMAIL  , new String[]{"recipient@example.com"});
    138.             i.putExtra(Intent.EXTRA_SUBJECT, "subject of email");
    139.             i.putExtra(Intent.EXTRA_TEXT   , "body of email");
    140.             try {
    141.                 context.startActivity(Intent.createChooser(i, "Send mail..."));
    142.             } catch (android.content.ActivityNotFoundException ex) {
    143.                 Toast.makeText(context, "There are no email clients installed.", Toast.LENGTH_SHORT).show();
    144.             }
    145.         }
    146.     });
    147. }
    148.  
    149. @Override
    150. public int getChildrenCount(int groupPosition) {
    151.     return this._listDataChild.get(this.itemList.get(groupPosition).getEmpName()).size();
    152. }
    153.  
    154. @Override
    155. public Object getGroup(int groupPosition) {
    156.     return this.itemList.get(groupPosition);
    157. }
    158.  
    159. @Override
    160. public int getGroupCount() {
    161.     return this.itemList.size();
    162. }
    163.  
    164. @Override
    165. public long getGroupId(int groupPosition) {
    166.     return groupPosition;
    167. }
    168.  
    169. @Override
    170. public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) {
    171.  
    172.     PendingBO pendingBO = (PendingBO) getGroup(groupPosition);
    173.     if (convertView == null) {
    174.         LayoutInflater infalInflater = (LayoutInflater) this.context
    175.                 .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    176.         convertView = infalInflater.inflate(R.layout.pending_approval_expandable_heading, null);
    177.         viewHolder1 = new ViewHolderItem();
    178.         viewHolder1.lblListHeader = (TextView) convertView.findViewById(R.id.lblListHeader);
    179.  
    180.         convertView.setTag(viewHolder1);
    181.     }else{
    182.         viewHolder1 = (ViewHolderItem) convertView.getTag();
    183.     }
    184.  
    185.     viewHolder1.lblListHeader.setTypeface(null, Typeface.BOLD);
    186.     viewHolder1.lblListHeader.setText(pendingBO.getEmpName());
    187.  
    188.     return convertView;
    189. }
    190.  
    191. @Override
    192. public boolean hasStableIds() {
    193.     return false;
    194. }
    195.  
    196. @Override
    197. public boolean isChildSelectable(int groupPosition, int childPosition) {
    198.     return true;
    199. }
    200.  
    201. public void clickContinue(View v){
    202.     empName = AppController.getInstance().pendingBO.getEmpName();
    203.     callAddLeadEmp(AppController.getInstance().pendingBO.getEmpID());
    204. }
    205.  
    206. public void clickYes(View v){
    207.     callDeadLeadApproval();
    208. }
    209. public void clickReassign(View v){
    210.     ShowEmpList();
    211. }
    212. public void ShowEmpList(){
    213.     String[] empArr = new String[memberList.size()];
    214.     for(int i=0;i<memberList.size();i++){
    215.         empArr[i]=memberList.get(i).getName();
    216.     }
    217.  
    218.     new MaterialDialog.Builder(context)
    219.             .title("Select BDE Name")
    220.             .items(empArr)
    221.             .alwaysCallSingleChoiceCallback()
    222.             .itemsCallbackSingleChoice(-1, new MaterialDialog.ListCallbackSingleChoice() {
    223.                 @Override
    224.                 public boolean onSelection(MaterialDialog dialog, View view, int which, CharSequence text) {
    225.                     empId = memberList.get(which).getId();
    226.                     empName =  text.toString();
    227.                     Log.e("Emp Name",empName);
    228.                     return true;
    229.                 }
    230.             })
    231.             .positiveText("Choose & Submit")
    232.  
    233.             .onPositive(new MaterialDialog.SingleButtonCallback() {
    234.                 @Override
    235.                 public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
    236.                     if(empId.length()<=0){
    237.                         Utility.ShowLongNotification(context, ErrorUtil.MEMBER_SELECTION_BLANK);
    238.                         return;
    239.                     }
    240.                     callAddLeadEmp(empId);
    241.                     dialog.dismiss();
    242.                 }
    243.             })
    244.             .show();
    245.  
    246. }
    247.  
    248. public void clickNote(View v){
    249.     Intent intent = new Intent(context, NoteActivity.class);
    250.  
    251.     AppController ctrl = AppController.getInstance();
    252.     ctrl.leadId = ctrl.pendingBO.getLead().getId();
    253.     ctrl.noteList = ctrl.pendingBO.getLead().getNoteBOList();
    254.     context.startActivity(intent);
    255. }
    256.  
    257. public void callMemberList(){
    258.     AppController ctrl = AppController.getInstance();
    259.     MemberListAPI api = new MemberListAPI(context,this);
    260.     api.processMemberList(ctrl.mEmpId);
    261. }
    262.  
    263. public void callDeadLeadApproval(){
    264.     AppController ctrl = AppController.getInstance();
    265.     DeadLeadPendingAPI api = new DeadLeadPendingAPI(context,this);
    266.     api.processDeadLead(""+ctrl.pendingBO.getLead().getId());
    267. }
    268. public void callAddLeadEmp(String empID){
    269.     AppController ctrl = AppController.getInstance();
    270.     AddLeadEmpAPI api = new AddLeadEmpAPI(context,this);
    271.     api.processAddLeadEmp(empID, LMSUtil.PRE_VISIT,""+ctrl.pendingBO.getLead().getId());
    272.  
    273. }
    274. }
    PendingExpandableActivity.java:

    Code (Text):
    1. public class PendingExpandableActivity extends Activity implements NetworkCallback{
    2.  
    3. ExpandableListAdapter listAdapter;
    4. ExpandableListView expListView;
    5. AppController delegate;
    6. private List<PendingBO> listDataHeader;
    7. private HashMap<String, List<LeadBO>> listDataChild;
    8. private static Context context;
    9. private GridLayoutManager lLayout;
    10. private SwipeRefreshLayout mSwipeRefreshLayout;
    11. private Button homeBtn;
    12.  
    13. @Override
    14. protected void onCreate(Bundle savedInstanceState) {
    15.     super.onCreate(savedInstanceState);
    16.  
    17.     requestWindowFeature(Window.FEATURE_NO_TITLE);
    18.     setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
    19.     setContentView(R.layout.fragment_pending_expandablelistview);
    20.  
    21.     mSwipeRefreshLayout = (SwipeRefreshLayout)findViewById(R.id.swipeRefreshLayout);
    22.     homeBtn= (Button) findViewById(R.id.homeBtn);
    23.  
    24.     mSwipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
    25.         @Override
    26.         public void onRefresh() {
    27.             // Refresh items
    28.             callDeadLead();
    29.         }
    30.     });
    31.  
    32.     // get the listview
    33.     expListView = (ExpandableListView) findViewById(R.id.lvExp);
    34.  
    35.     listDataHeader = new ArrayList<PendingBO>();
    36.     listDataChild = new HashMap<String, List<LeadBO>>();
    37.  
    38.     listAdapter = new ExpandableListAdapter(this, listDataHeader, listDataChild);
    39.     expListView.setAdapter(listAdapter);
    40.  
    41.     expListView.setOnGroupClickListener(new ExpandableListView.OnGroupClickListener() {
    42.  
    43.         @Override
    44.         public boolean onGroupClick(ExpandableListView parent, View v,
    45.                                     int groupPosition, long id) {
    46.             PendingBO pendingBO = listDataHeader.get(groupPosition);
    47.             if (pendingBO.getStatus() == 0) {
    48.                 pendingBO.setStatus(1);
    49.             } else {
    50.                 pendingBO.setStatus(0);
    51.             }
    52.             listAdapter.notifyDataSetChanged();
    53.             return false;
    54.         }
    55.     });
    56.  
    57.     // Listview Group expanded listener
    58.     expListView.setOnGroupExpandListener(new ExpandableListView.OnGroupExpandListener() {
    59.         @Override
    60.         public void onGroupExpand(int groupPosition) {
    61.         }
    62.     });
    63.  
    64.     // Listview Group collasped listener
    65.     expListView.setOnGroupCollapseListener(new ExpandableListView.OnGroupCollapseListener() {
    66.         @Override
    67.         public void onGroupCollapse(int groupPosition) {
    68.  
    69.         }
    70.     });
    71.  
    72.     // Listview on child click listener
    73.     expListView.setOnChildClickListener(new ExpandableListView.OnChildClickListener() {
    74.         @Override
    75.         public boolean onChildClick(ExpandableListView parent, View v,
    76.                                     int groupPosition, int childPosition, long id) {
    77.             return false;
    78.         }
    79.     });
    80. }
    81.  
    82. @Override
    83. protected void onResume() {
    84.     super.onResume();
    85.     context=PendingExpandableActivity.this;
    86.     callDeadLead();
    87. }
    88.  
    89. private void callDeadLead() {
    90.     AppController ctrl = AppController.getInstance();
    91.     DeadListAPI api = new DeadListAPI(this,this);
    92.     api.processDeadLead(ctrl.mEmpId);
    93. }
    94.  
    95. @Override
    96. protected void onPause() {
    97.     super.onPause();
    98.     Log.e("activity","onPause()");
    99. }
    100.  
    101. public boolean onKeyDown(int keyCode, KeyEvent event) {
    102.     if (keyCode == KeyEvent.KEYCODE_BACK) {
    103.         back();
    104.         finish();
    105.     }
    106.     return super.onKeyDown(keyCode, event);
    107. }
    108.  
    109. private void back() {
    110.     Intent i=new Intent(PendingExpandableActivity.this,ToDoListActivity.class);
    111.     i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
    112.     startActivity(i);
    113. }
    114.  
    115. @Override
    116. public void updateScreen(String data, String tag) {
    117.     if(tag.compareTo(ApiUtil.TAG_DEAD_LEAD_API)==0){
    118.         listDataHeader = PendingListParsar.parsePendingBo(data);
    119.     //    makePendingApprovals();
    120.         mSwipeRefreshLayout.setRefreshing(false);
    121.     }
    122. }
    123.  
    124. public void makePendingApprovals(){
    125.     lLayout = new GridLayoutManager(this,1);
    126.  
    127.     RecyclerView rView = (RecyclerView)findViewById(R.id.cardList);
    128.     rView.setHasFixedSize(true);
    129.     rView.setLayoutManager(lLayout);
    130.     rView.setItemAnimator(new DefaultItemAnimator());
    131.  
    132.     PendingViewAdapter rcAdapter = new PendingViewAdapter(this, listDataHeader);
    133.     rView.setAdapter(rcAdapter);
    134. }
    135. }
     

    Advertisement

  2. HeavensSentSword

    HeavensSentSword Well-Known Member
    Rank:
    None
    Points:
    93
    Posts:
    134
    Joined:
    Jan 19, 2016

    Jan 19, 2016
    134
    36
    93
    Male
    Looks like your clearing the sharedPref here
    Code (Java):
    1. new SharedPreferencesClass().clear(ToDoListActivity.this);
    That is why you have to get all the data again.
     

Share This Page

Loading...