Skip to content Skip to sidebar Skip to footer

Android: Baseadapter Not Showing Elements

The app I'm struggling to make has a simple list and a button present in the bottom no matter what. My problem is that my custom BaseAdapter doesn't show elements. I know that sinc

Solution 1:

Your code almost perfect issue is return orase.size() in getcount() method,you are returning 0, add unimplemented methods in ListaOrase class. your ListaOrase should be like this:

classListaOraseextendsBaseAdapter{
    private Activity context;
    ArrayList<String> orase;

    publicListaOrase(Activity context){
        this.context=context;
        orase=new ArrayList<String>();
    }
    publicvoidadd(String string){
        orase.add(string);
    }

    public View getView (int position, View convertView, ViewGroup list)  {
        View element;
        if (convertView == null)
        {
         LayoutInflater inflater = context.getLayoutInflater();
         element = inflater.inflate(R.layout.lista, null);
        }
        else element = convertView;
        TextView elementLista=(TextView)element.findViewById(R.id.elementLista);    
        elementLista.setText(orase.get(position));
        Log.e("",orase.get(position));
        return element;
    }
    publicintgetCount() {
        // TODO Auto-generated method stubreturn orase.size();
    }
    public Object getItem(int position) {
        // TODO Auto-generated method stubreturnnull;
    }
    publiclonggetItemId(int position) {
        // TODO Auto-generated method stubreturn0;
    }

}

hope this helps

Solution 2:

getCount method was really returning 0 so consquently getView() wasn't being called. When I changed to:

getcount() {  
    return arrayObject.Size();
}

Post a Comment for "Android: Baseadapter Not Showing Elements"