我有一个作为 [x,y,z..] 的 Arraylist
。我想在 ListView
中使用此 ArrayList
[x,y,z..],但未调用 getview()
方法
我正在尝试这段代码:
public class CustomAdapter extends BaseAdapter
{
public static ArrayList<String> arr=new ArrayList<String>();
public Context Context;
private LayoutInflater inflater;
HashMap<String, String> map = new HashMap<String, String>();
public CustomAdapter(Context context, ArrayList<String> arr)
{
Context=context;
inflater=LayoutInflater.from(context);
arr=arr;
}
public int getCount()
{
// TODO Auto-generated method stub
return arr.size();
}
public Object getItem(int position)
{
// TODO Auto-generated method stub
return arr.get(position);
}
public long getItemId(int position)
{
// TODO Auto-generated method stub
return position;
}
public View getView(int position, View convertView, ViewGroup parent)
{
System.out.println(arr.get(posstion));
ViewHolder holder;
if (convertView == null)
{
convertView = inflater.inflate(R.layout.selecteditemlistview, null);
holder = new ViewHolder();
holder.textViewSelectedText = (TextView)convertView.findViewById(R.id.selectedtext);
convertView.setTag(holder);
}
else
{
holder = (ViewHolder) convertView.getTag();
}
holder.textViewSelectedText.setText(arr.get(position));
return convertView;
}
class ViewHolder
{
TextView textViewSelectedText = null;
}
}
System.out.println(arr.get(posstion));
这一行在 getview()
方法中,它没有打印值。请帮助我。
最佳答案
您应该在 ListView 上使用 setAdapter 函数以让它使用您的自定义适配器
编辑:CustomAdapter 构造函数中有错别字:代码应为
this.arr = arr
代替
arr = arr
关于android - getview 方法未在 android 中的自定义 listview 方法中调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10381391/