0
我在CustomAdapter爲靜態值的搜索和使用列表視圖節在裏面。有沒有爲SectionListView CustomAdapter的任何例子嗎?
我發現很多例子來簡單列表視圖,但希望科的ListView具有靜態數據,並有CustomAdapter的一些演示。
我在CustomAdapter爲靜態值的搜索和使用列表視圖節在裏面。有沒有爲SectionListView CustomAdapter的任何例子嗎?
我發現很多例子來簡單列表視圖,但希望科的ListView具有靜態數據,並有CustomAdapter的一些演示。
public class MultipleItemsList extends ListActivity {
private MyCustomAdapter mAdapter;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mAdapter = new MyCustomAdapter();
for (int i = 0; i < 50; i++) {
mAdapter.addItem("item " + i);
}
setListAdapter(mAdapter);
}
private class MyCustomAdapter extends BaseAdapter {
private ArrayList mData = new ArrayList();
private LayoutInflater mInflater;
public MyCustomAdapter() {
mInflater = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
public void addItem(final String item) {
mData.add(item);
notifyDataSetChanged();
}
@Override
public int getCount() {
return mData.size();
}
@Override
public String getItem(int position) {
return mData.get(position);
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
System.out.println("getView " + position + " " + convertView);
ViewHolder holder = null;
if (convertView == null) {
convertView = mInflater.inflate(R.layout.item1, null);
holder = new ViewHolder();
holder.textView = (TextView)convertView.findViewById(R.id.text);
convertView.setTag(holder);
} else {
holder = (ViewHolder)convertView.getTag();
}
holder.textView.setText(mData.get(position));
return convertView;
}
}
public static class ViewHolder {
public TextView textView;
}
}
你想使用客戶適配器? –
我可以知道更多的事情你究竟想要做 –
寫的「Android的ListView部分適配器」在谷歌! –