Wednesday, January 11, 2012

Android - Extending ListView and Instantiate with XML and AlertDialogs for itemSelect

Was doing a bit of coding and decided to demonstrate a way to create your own class which extends ListView. I wanted to manage specific code in regards to this listview and didnt want the code to be all over the place. Anywho, here is the source of a quick ListView showing names.

When you click on the items an AlertDialog box appears indicating what you clicked on.

NOTE: the XML files below should go in res/layout folder of your project.

Main.xml Make sure to make change to package name!

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android=""
    android:orientation="vertical" >



row.xml This layout defines how each row is going to look like. This has a picture and name

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android=""
    android:orientation="horizontal" >

        android:src="@drawable/ic_launcher" >

        android:textSize="20dp" >


MainActivity (beginning of program)

import android.os.Bundle;

public class ViewTestActivity extends Activity 
    /** Called when the activity is first created. */
    public void onCreate(Bundle savedInstanceState) 

TestListView Class extending ListView

package com.daish.viewtest;

import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;

public class TestListView extends ListView
 private ArrayAdapter<String> test;
 String[] testItems = {"Larry", "John", "Gary"};
 //If built programmatically
 public TestListView(Context context)
 //This example uses this method since being built from XML
 public TestListView(Context context, AttributeSet attrs)
  super(context, attrs);
 //Build from XML layout 
 public TestListView(Context context, AttributeSet attrs, int defStyle)
  super(context, attrs, defStyle);
 public void init()
  test = new ArrayAdapter<String>(getContext(),R.layout.row, , testItems);
  setOnItemClickListener(new ListSelection());
 private class ListSelection implements OnItemClickListener

  public void onItemClick(AdapterView<?> parent, View view, int position,
    long id)
   AlertDialog.Builder builder = new AlertDialog.Builder(getContext());
   builder.setMessage("You pressed item #" + (position+1));
   builder.setPositiveButton("OK", null);;

The code above should give you this:

Friday, January 6, 2012

Recovering Cisco IP Phone 7940 / 7960

These Cisco IP phones are a pain to setup. I was given the task to setup 6 Cisco IP phones. Out of the batch 2 did not boot up to the point where we could access the settings. On the Cisco 7940 we received TFTP timeout o / A and just remained there. The other was a Cisco 7960 and gave an error Application Protocol Invalid. I was able to recover the phones by doing the following:

CAUTION: The instructions configure phone to work as SIP Phones not Skinny SCCP.

You will need the following:

  1. TFTpd32
  2. Cisco IP Phone firmware (I used P0S3-8-12-00)
  3. Cisco IP Phone configuration files If you do not know how to setup config files, check out the site
  4. Switch
  5. Computer


  1. Download TFTpd32 at and firmware and configuration files.
  2. Grab a computer and install TFTpd32. Unzip firmware and configuration files to a folder. To be safe, setup configuration files to have SIP[Phone MAC Address].cnf and SEP[Phone MAC Address].cnf.xml (Check website above if you don't know how to setup configs)
  3. Disconnect computer from network and plug into switch (Switch should only have computer and phone. Leave Cisco Phone powered off while you setup TFTpd32)
  4. Set the computer IP address to MASK Bring up TFTpd32 and go to settings.
    • Under Global Tab, only enable TFTP Server and DHCP Server.
    • Click on TFTP tab. Set Base Directory to the location of the folder where Cisco IP firmware and configuration files are. Set TFTP security to none.
    • Click on DHCP tab and set IP pool starting address to Set pool to 5 or something like that. Default router put mask Additional option 66 in small box and ip in the box next to it. Uncheck Ping Address before assignation and Persistant leases.
  5. Hit OK and Restart TFTpd32.

  6. While your TFTP is running, power on the Cisco IP phone. If all goes well, TFTpd32 will log the connection and show the files it requests.

  7. The phones will show upgrading firmware.

  8. Phones should now boot up completely once installation is complete.