0

I have a listview with and image and per row 2 lines. in the first line i have a simple text stored in a array, the second line also, but what i would like to know how it can change dynamically the second line with the installed or not app status.

this is the code:

String[] tools = new String[] { "tool 1", "tool 2", "tool 3", "tool 4", "tool 5" };

    // Array integer que apunta a las imagenes en /res/drawable-ldpi/
    int[] flags = new int[]{
            R.drawable.image1,
            R.drawable.image2,
            R.drawable.image3,
            R.drawable.image4,
            R.drawable.image5
    };

    // Array string donde van la descripcion
    String[] status = new String[]{
        "Status",
        "Status",
        "Status",
        "Status",
        "Status"

    };


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

        List<HashMap<String,String>> aList = new ArrayList<HashMap<String,String>>();        

        for(int i=0;i<5;i++){
            HashMap<String, String> hm = new HashMap<String,String>();
            hm.put("txt", tools[i]);
            hm.put("cur", status[i]);
            hm.put("flag", Integer.toString(flags[i]) );            
            aList.add(hm);        
        }

        String[] from = { "flag","txt","cur" };
        int[] to = { R.id.flag,R.id.txt,R.id.cur};        
        SimpleAdapter adapter = new SimpleAdapter(getBaseContext(), aList, R.layout.listview_layout, from, to);

With this link How to check programmatically if an application is installed or not in Android? i have the function to know if the app is installed or not, but how i can load it in the status array? and how i add it to my source?

Community
  • 1
  • 1
ruben
  • 47
  • 9

1 Answers1

1

First you set the value of app installed status to your array.Like,

String statustext=IfAppinstalled();// assuming IfAppinstalled() is the function to get status.

Now set this value to your array like,

status[1]=statustext;

and set this to your listview,

Here is the code to check an app is istalled or not,

private boolean appInstalledOrNot(String uri)
    {
        PackageManager pm = getPackageManager();
        boolean app_installed = false;
        try
        {
               pm.getPackageInfo(uri, PackageManager.GET_ACTIVITIES);
               app_installed = true;
        }
        catch (PackageManager.NameNotFoundException e)
        {
               app_installed = false;
        }
        return app_installed ;
}

and call it like,

 boolean installed  =   appInstalledOrNot("com.Ch.Example.pack");  
        if(installed)
        {

          //its installed, do ur stuff

        }
        else
        {
            //its not installed, do ur stuff
        }
Basim Sherif
  • 5,384
  • 7
  • 48
  • 90
  • thanks i was suspecting to do something like that. One las question. there is a simple way to check if an apk is installed or not? i programmed something but not working. http://pastebin.com/6kJKNHAA , thanks for your help i really apreciate it :) – ruben May 30 '13 at 12:42
  • Ohh cool, let me try it later(now i dont have the complete code here), and i will give you my feedback!, thanks a lot – ruben May 30 '13 at 12:48
  • done :), i will let you how it went, but normally with that answer its enough ^^ – ruben May 30 '13 at 12:59
  • i tried and in the first line and is not recognizing "IfAppinstalled()" i changed it to "appInstalledOrNot" and nothing also. any idea? thanks so much – ruben May 30 '13 at 15:23
  • you should use boolean installed = appInstalledOrNot("com.Ch.Example.pack"); Here the value of "installed" will be true, if the app is installed.And the value will be false, if it is not installed. – Basim Sherif May 31 '13 at 04:46
  • here in pastebin i wrote a little resume about what i want, beacuse im not understanding too much, maybe with this you can undesrtand better. http://pastebin.com/X61icJis thank you very much, and sorry for the incovenience, i just need to make it work!!! :) – ruben May 31 '13 at 10:55