<span style="white-space:pre"> </span>private ListView listview;
private ArrayList list;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
listview = (ListView) findViewById(R.id.listview);
list = new ArrayList();
list.add(0, "1");
list.add(1, "2");
list.add(2, "3");
listview.setAdapter(new MyAdapter());
}
private class MyAdapter extends BaseAdapter {
@Override
public int getCount() {
return list.size();
}
@Override
public Object getItem(int postion) {
return list.get(postion);
}
@Override
public long getItemId(int postion) {
return postion;
}
public class HolderView {
public TextView mytext;
}
@Override
public View getView(int postion, View contentView, ViewGroup parent) {
HolderView holder;
if (contentView == null) {
holder = new HolderView();
contentView = View.inflate(MainActivity.this, R.layout.item,null);
holder.mytext = (TextView) contentView.findViewById(R.id.mytext);
contentView.setTag(holder);
} else {
holder = (HolderView) contentView.getTag();
}
holder.mytext.setText(list.get(postion).toString());
return contentView;
}
}