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?
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
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.