我正试图让它添加,并且没有任何事情发生。我已经对我的arrrayadapter做了调整,它应该可以工作。
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) ;
//this.setListAdapter(new ArrayAdapter<String>(this,R.layout.row));
final ArrayList<String> items = new ArrayList<String>();
//this.setListAdapter(new TTAdapterView(this,items));
final TTAdapterView aa = new TTAdapterView(this,items);
//final ArrayAdapter<String> aa = new ArrayAdapter<String>(
// 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();
}
});
}
}
public class TTAdapterView extends ArrayAdapter<String> {
private final Activity context1;
private final ArrayList<String> items;
public TTAdapterView(Activity context, ArrayList<String> items){
super(context,R.layout.row,items);
this.context1 = context;
this.items = items;
}
static class ViewHolder{
public TextView task;
public Chronometer time;
public CheckBox complete;
}
@Override
public View getView(int position, View convertView, ViewGroup parent){
ViewHolder holder;
View rowView = convertView;
if(rowView==null){
LayoutInflater vi = context1.getLayoutInflater();
rowView = vi.inflate(R.layout.row, null, true);
holder = new ViewHolder();
holder.task = (TextView) rowView.findViewById(R.id.textView1);
holder.time = (Chronometer) rowView.findViewById(R.id.chronometer1);
holder.complete = (CheckBox) rowView.findViewById(R.id.checkBox1);
rowView.setTag(holder);
}
else{
holder = (ViewHolder) rowView.getTag();
}
return rowView;
}
}
知道为什么不更新?感谢
答案 0 :(得分:2)
您未在listview -_-中设置行的内容!
至少你应该在getView中执行此操作:
String taskText=items.get(position);
holder.task.setText(taskText);
答案 1 :(得分:0)
这个答案是对的,
String taskText=items.get(position);
holder.task.setText(taskText);