I am trying to add a footer to my ListView. If I create the buttons via code and add the Views I dont' have any problems. If I try use an xml file and getLayoutInflator I get a "Source not found" exception. I found a lot of similiar exceptions but none that were very helpful. Can anyone point me in the right direction?
I've pulled most of this from an example here: http://www.softwarepassion.com/android-series-custom-listview-items-and-adapters/
Here is my activity:
package nmcbride.android.androidpowercalc;
import java.util.ArrayList;
import android.app.ListActivity;
import android.app.ProgressDialog;
import android.content.Context;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;
public class AndroidPowerCalc extends ListActivity {
/** Called when the activity is first created. */
private ProgressDialog m_ProgressDialog = null;
private ArrayList<Calculation> m_calculations = null;
private CalculationAdapter m_adapter;
private Runnable viewCalculations;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
m_calculations = new ArrayList<Calculation>();
this.m_adapter = new CalculationAdapter(this, R.layout.history_calculation_layout, m_calculations);
// ListView lv = getListView();
// LayoutInflater inflater = getLayoutInflater();
// ViewGroup footer = (ViewGroup)inflater.inflate(R.layout.history_footer, lv, false);
// lv.addHeaderView(footer, null, false);
View history_footer = getLayoutInflater().inflate(R.layout.history_footer, getListView());
getListView().addFooterView(history_footer);
// addButton = new Button(this);
// addButton.setText("Add");
// this.getListView().addFooterView(addButton);
setListAdapter(m_adapter);
viewCalculations = new Runnable(){
//@Override
public void run() {
getCalculations();
}
};
Thread thread = new Thread(null, viewCalculations, "MagentoBackground");
thread.start();
m_ProgressDialog = ProgressDialog.show(AndroidPowerCalc.this,
"Please wait...", "Retrieving data ...", true);
}
private Runnable returnRes = new Runnable() {
//@Override
public void run() {
if(m_calculations != null && m_calculations.size() > 0){
m_adapter.notifyDataSetChanged();
for(int i=0;i<m_calculations.size();i++)
m_adapter.add(m_calculations.get(i));
}
m_ProgressDialog.dismiss();
m_adapter.notifyDataSetChanged();
}
};
private void getCalculations(){
try{
m_calculations = new ArrayList<Calculation>();
Calculation o1 = new Calculation();
o1.setCalculationString("8+8*8");
Calculation o2 = new Calculation();
o2.setCalculationString("9+9*9");
m_calculations.add(o1);
m_calculations.add(o2);
Thread.sleep(5000);
Log.i("ARRAY", ""+ m_calculations.size());
} catch (Exception e) {
Log.e("BACKGROUND_PROC", e.getMessage());
}
runOnUiThread(returnRes);
}
public String doCalc(String calcString) {
return calcString;
}
private class CalculationAdapter extends ArrayAdapter<Calculation> {
private ArrayList<Calculation> items;
public CalculationAdapter(Context context, int textViewResourceId, ArrayList<Calculation> items) {
super(context, textViewResourceId, items);
this.items = items;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View v = convertView;
if (v == null) {
LayoutInflater vi = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
v = vi.inflate(R.layout.history_calculation_layout, null);
}
Calculation c = items.get(position);
if (c != null) {
TextView tt = (TextView) v.findViewById(R.id.computation_string);
TextView bt = (TextView) v.findViewById(R.id.result_string);
if (tt != null) {
tt.setText("Computation: " + c.getCalculationString()); }
if(bt != null){
bt.setText("Result: "+ c.getCalculationString());
}
}
return v;
}
}
}
Thank you in andvance.