Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6365061
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T00:14:44+00:00 2026-05-25T00:14:44+00:00

Anyone please clarify my doubts in this program : – BackUpActivity.java : – public

  • 0

Anyone please clarify my doubts in this program : –

BackUpActivity.java : –

public class BackUpActivity extends Activity
{
//Use ArrayList to store the installed non-system apps
ArrayList<AppInfo> appList = new ArrayList<AppInfo>();

//ListView app_listView;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

//        List<ApplicationInfo> packages = getPackageManager().getInstalledApplications(0);
    List<PackageInfo> packages = getPackageManager().getInstalledPackages(0);
    for(int i=0; i<packages.size(); i++)
    { 
        PackageInfo packageInfo = packages.get(i);
        AppInfo tmpInfo = new AppInfo();
        tmpInfo.appName =     packageInfo.applicationInfo.loadLabel(getPackageManager()).toString(); 
        tmpInfo.packageName = packageInfo.packageName; 
        tmpInfo.versionName = packageInfo.versionName; 
        tmpInfo.versionCode = packageInfo.versionCode; 
        tmpInfo.appIcon = packageInfo.applicationInfo.loadIcon(getPackageManager());
        //  Only display the non-system app info
        if((packageInfo.applicationInfo.flags&ApplicationInfo.FLAG_SYSTEM)==0)
        {
            appList.add(tmpInfo);
        }
    }
    for(int i=0;i<appList.size();i++)
    {
        appList.get(i).print();
    }

    //Populate data to listView
    ListView app_listView=(ListView)findViewById(R.id.listview1);
    AppAdapter appAdapter=new AppAdapter(BackUpActivity.this,appList);

    //app_listView.setAdapter(appAdapter);
    app_listView.setDividerHeight(5);
    if(app_listView!=null)
    {
        app_listView.setAdapter(appAdapter);
    }
}
public class AppAdapter extends BaseAdapter 
{
    Context context;
    ArrayList<AppInfo> dataList=new ArrayList<AppInfo>();
    public AppAdapter(Context context,ArrayList<AppInfo> inputDataList)
    {
        this.context=context;
        dataList.clear();
        for(int i=0;i<inputDataList.size();i++)
        {
            dataList.add(inputDataList.get(i));
        }
    }
    @Override
    public int getCount()
    {
        // TODO Auto-generated method stub
        return dataList.size();
    }

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

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

    @Override
    public View getView(int position, View convertView, ViewGroup parent)
    {           
        View v=convertView;
        final AppInfo appUnit=dataList.get(position);
        if(v==null)
        {
            LayoutInflater vi=(LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            v=vi.inflate(R.layout.app_row, null);
            v.setClickable(true);
        }
        TextView appName=(TextView)v.findViewById(R.id.appName);
        ImageView appIcon=(ImageView)v.findViewById(R.id.icon);
        if(appName!=null)
            appName.setText(appUnit.appName);
        if(appIcon!=null)
            appIcon.setImageDrawable(appUnit.appIcon);
        return v;
    }
}
public boolean onCreateOptionsMenu(Menu menu) 
 {
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.menu, menu);
    return true;
 }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) 
    {
        switch (item.getItemId())
        {               
            case R.id.BackUp:
            try
            {
                backup();
            }catch(Exception e){}                                   
//                  finish();
                break;
            case R.id.CheckAll:
                try
                {
                    checkall();
                }catch(Exception e){e.notify();}
                break;
            case R.id.Cancel:
            try
            {
                cancel();
            }catch(Exception e){}
            break;
        }
        return true;
    }
    public void backup()
    {
        Toast.makeText(this, "Backup Data", Toast.LENGTH_SHORT).show();
    }
    public void checkall()
    {
        CheckBox c = (CheckBox)this.findViewById(R.id.checkBox1);
        if (c.isChecked())
        { 
            c.setChecked(false); 
        } 
        else 
        {
            c.setChecked(true);
        }
    }
    public void cancel()
    {
        finish();
    }
}

AppInfo.java

package com.android.backup;

import android.graphics.drawable.Drawable;
import android.util.Log;

public class AppInfo 
{
public String appName="";
public String packageName="";
public String versionName="";
public int versionCode=0;
public Drawable appIcon=null;

public void print()
{
    Log.v("app","Name:"+appName+" Package:"+packageName);
    Log.v("app","Name:"+appName+" versionName:"+versionName);
    Log.v("app","Name:"+appName+" versionCode:"+versionCode);
}
}

It’s showing the results not properly, if i’m going to select the checkall button, it’ll not work properly.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T00:14:45+00:00Added an answer on May 25, 2026 at 12:14 am

    You basically need some data structure to keep track of checked items.
    you can use boolean array in your custom adapter.

    for more info refer this link Custom listview with checkbox problem

    listview with checkbox

    if you are looking for an example try this http://appfulcrum.com/?p=281 tutorial which solves the checkbox problem in listview using shared preferences.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can anyone please clarify what this query will return ? SELECT TestCase FROM MyTable
I have the following code, could anyone please clarify my doubt below. public static
could anyone please clarify the meaning of line generalizes the tag object's storage of
Could anyone please tell what are the important use cases of IdentityHashMap ?
Can anyone please tell me when should I use MessageContracts and when should I
I've a small doubt in my mind; could anyone please clarify me is the
Could anyone please clarify the difference between continuous and discrete attributes? Thanks.
public class Elevator () { Button firstFloorbutton = ButtonFactory.getButtonInstance(this, 1); Button secondFloorbutton = ButtonFactory.getButtonInstance(this,
[Edit #3] - to anyone reading this question: do not under any circumstance use
Could anyone please clarify the defination of attribute? for example, in the following code,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.