I am having an Arraylist as [x,y,z..]. I want this ArrayList [x,y,z..] in ListView but getview() method is not getting invoked
I am trying this code :
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));
This line is inside getview() method and it is not printing the values.. please help me.
You should use the setAdapter function on the ListView to let it use your custom adapter
EDIT: There is a typo in the CustomAdapter constructor: the code should read
instead of