ListView with Custom ArrayAdapter not updating
- by Intelwalk
I am currently trying to return a custom view of a textview, chrono, and checkbox. I have overriden the getView method but I am not sure if I did it correctly. I would appreciate some comments on the arrayadapter. It currently does not update in my application. Thanks!
main java
public class TaskTracker extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button addButton;
addButton=(Button)findViewById(R.id.button1);
ListView myListView= (ListView)findViewById(R.id.listView1);
final EditText myEditText= (EditText)findViewById(R.id.editText1) ;
//final ArrayList<String> taskitems = new ArrayList<String>();
final TTAdapterView aa = new TTAdapterView(this);
// aa = new ArrayAdapter<String>(this, 0);
myListView.setAdapter(aa);
addButton.setOnClickListener(new OnClickListener(){
public void onClick(View v){
aa.add(myEditText.getText().toString());
//taskitems.add(count, myEditText.getText().toString());
aa.notifyDataSetChanged();
myEditText.setText("");
myEditText.requestFocus();
}
});
}
}
ArrayAdapter
public class TTAdapterView extends ArrayAdapter<String> {
public View v;
public TTAdapterView(Context context){
super(context,R.layout.row);
}
@Override
public View getView(int position, View convertView, ViewGroup parent){
this.v = convertView;
if(v==null){
LayoutInflater vi = (LayoutInflater)getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
v = vi.inflate(R.layout.row, null);
}
return v;
}