ListView with Custom ArrayAdapter not updating

Posted by Intelwalk on Stack Overflow See other posts from Stack Overflow or by Intelwalk
Published on 2011-04-11T15:06:21Z Indexed on 2011/11/30 1:51 UTC
Read the original article Hit count: 483

Filed under:

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;
}

© Stack Overflow or respective owner

Related posts about android