Jan 5, 2014

List System Properties of Android system

The example call getProperties() method of java.lang.System class to get the system properties. It modify the custom ListView from last example "Implement OnItemClickListener for custom ListView" and "Create custom ListView of custom object".

List System Properties
List System Properties
package com.example.androidcustomlistview;

import java.util.ArrayList;
import java.util.Enumeration;
import java.util.Properties;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.BaseAdapter;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;
import android.app.Activity;
import android.content.Context;

public class MainActivity extends Activity {

 private class SystemProperties{
  private String propertiesName;
  private String properties;
  SystemProperties(String pName, String p){
   propertiesName = pName;
   properties = p; 
  public String getPropertiesName(){
   return propertiesName;
  public String getpPoperties(){
   return properties;

 protected void onCreate(Bundle savedInstanceState) {
  ListView listView = (ListView)findViewById(R.id.listview);
  //Init ArrayList of MyObject
  ArrayList<SystemProperties> myPropertyList = new ArrayList<SystemProperties>();
  //get System Properties
  Properties properties = System.getProperties();
  Enumeration<String> propEnum = 
            String propName = propEnum.nextElement();
            String prop = System.getProperty(propName);
            SystemProperties nexProp = new SystemProperties(propName, prop);
  MyAdapter myAdapter = new MyAdapter(this, myPropertyList);
  listView.setOnItemClickListener(new OnItemClickListener(){

   public void onItemClick(AdapterView<?> parent, 
     View view, int position, long id) {
    SystemProperties clickedObj = (SystemProperties)parent.getItemAtPosition(position);
      clickedObj.getPropertiesName() + ":\n" +

 private class MyAdapter extends BaseAdapter {
  private ArrayList<SystemProperties> myList;
  private Activity parentActivity;
     private LayoutInflater inflater; 
     public MyAdapter(Activity parent, ArrayList<SystemProperties> l) {
      parentActivity = parent;
         inflater = (LayoutInflater)parentActivity

  public int getCount() {
   return myList.size();

  public Object getItem(int position) {
   return myList.get(position);

  public long getItemId(int position) {
   return position;

  public View getView (int position, View convertView, 
    ViewGroup parent) {
   View view = convertView;
             view = inflater.inflate(R.layout.row, null);
         TextView text1 = (TextView)view.findViewById(R.id.text1);
         TextView text2 = (TextView)view.findViewById(R.id.text2);
         SystemProperties myObj = myList.get(position);
         return view;

For thw XMLs of the main layout and the ListView row layout, refer to the post "Create custom ListView of custom object".

Next: Implement auto scroll marquee TextView in ListView

No comments:

Post a Comment

Infolinks In Text Ads