大佬教程收集整理的这篇文章主要介绍了Android中使用ArrayAdapter和ListView的大型数据集,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
package example.VariableListView; import java.util.ArrayList; import android.app.ListActivity; import android.os.bundle; import android.widget.ArrayAdapter; public class variablelistview extends ListActivity { @Override public void onCreate(Bundle iciclE) { super.onCreate(iciclE); ArrayList<Integer> intItems = new ArrayList<Integer>(); for (int ii = 0; ii < 100; ii++) { intItems.add(ii); } this.setlistadapter(new ArrayAdapter<Integer>(this,android.R.layout.simple_list_item_1,intItems)); }@H_262_7@} @H_262_7@提前感谢任何和所有的帮助.
public class IntRangeAdapter extends BaseAdapter { private LayoutInflater mInflater; privatE int mItemresource; public intRangeAdapter(Context context,int itemLayout) { // We'll use this to generate new item layouts mInflater = LayoutInflater.from(context); // This is the layout resource we'll use for each item mItemresource = itemLayout; } public int getCount() { // Since this adapter presents all positive Integers,// we have Integer.max_value items. return Integer.max_value; } public Object getItem(int position) { // Each item is simply its position index. return position; } public long getItemId(int position) { // Our items won't change and we don't need stable IDs,// so the position of an item is also its ID. return position; } public View getView(int position,View convertView,ViewGroup parent) { if (convertView == null) { // Inflate a new item layout if we weren't given an exisTing // one to reuse via the convertView parameter. convertView = mInflater.inflate(mItemresource,parent,falsE); } // Find the TextView where we will label the item. // (This can be optimized a bit for more complex layouts // but we won't bother for this example.) TextView tv = (TextView) convertView.findViewById(android.R.id.text1); // Set the item text based on its position. tv.setText("Item " + position); return convertView; } }@H_262_7@从您发布的活动代码中使用它将是一个更改您的setAdapter调用并删除循环以设置数据的问题:
this.setlistadapter(new IntRangeAdapter(this,android.R.layout.simple_list_item_1));@H_262_7@如果您想了解更多关于使用ListViews的信息,Google I / O 2010的这个演讲给出了一个不错的介绍:@L_673_34@
以上是大佬教程为你收集整理的Android中使用ArrayAdapter和ListView的大型数据集全部内容,希望文章能够帮你解决Android中使用ArrayAdapter和ListView的大型数据集所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。