Anyone interested in using an
XML layout with the IconifiedTextListAdapter, try this:
Delete this (in IconifiedTextListAdapter.java):
Using java Syntax Highlighting
/** @param convertView The old view to overwrite, if one is passed
* @returns a IconifiedTextView that holds wraps around an IconifiedText */
public View getView(int position, View convertView, ViewGroup parent) {
IconifiedTextView btv;
if (convertView == null) {
btv = new IconifiedTextView(mContext, mItems.get(position));
} else { // Reuse/Overwrite the View passed
// We are assuming(!) that it is castable!
btv = (IconifiedTextView) convertView;
btv.setText(mItems.get(position).getText());
btv.setIcon(mItems.get(position).getIcon());
}
return btv;
}
Parsed in 0.038 seconds, using
GeSHi 1.0.8.4
and replace it with this:
Using java Syntax Highlighting
/** Bind our Views */
public View getView(int position, View convertView, ViewGroup parent) {
/** Inflate our Context */
LayoutInflater inflater = (LayoutInflater)mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
/** Fill our Views*/
if(convertView == null) {
convertView = inflater.inflate(R.layout.list_rows, parent, false);
}
((TextView)convertView.findViewById(R.id.text1)).setText(mItems.get(position).getText());
((ImageView)convertView.findViewById(R.id.icon)).setImageDrawable(mItems.get(position).getIcon());
return convertView;
}
Parsed in 0.038 seconds, using
GeSHi 1.0.8.4
In CallLogDisplayer.java add this line directly under "super.onCreate(savedInstanceState) {"
Using java Syntax Highlighting
setContentView(R.layout.main);
Parsed in 0.035 seconds, using
GeSHi 1.0.8.4
You must now create a list_rows.xml file in your layout folder with the appropriate styling for R.id.text1 and R.id.icon. Your main.xml should look something like this:
Using xml Syntax Highlighting
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<ListView android:id="@android:id/list"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
<TextView android:id="@android:id/empty"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="Nothing to display"
android:gravity="center"
android:textAppearance="?android:attr/textAppearanceLarge" />
</LinearLayout>
Parsed in 0.003 seconds, using
GeSHi 1.0.8.4
Finally, clean up:
delete the IconifiedTextView.java file, as it is no longer needed.
I hope this helps some people. Styling in XML is preferable in Android, as it better accommodates many api resources. I am new to Java/Android so this may not be the "correct way" or bug-proof in any way. Works well for me.
Feel free to ask me for help with this if you can't figure it out. I know how hard it is for us new guys.
- iPaul Pro