1

Solve the mystery of populating a listview through a custom adapter, which is being passed multiple arraylists as defined below.

MAIN ACTIVITY: we declare the arraylists:

private static ArrayList<Integer> img_challengeicon_values;
static {
    img_challengeicon_values = new ArrayList<Integer>();
    img_challengeicon_values.add(R.drawable.actionbar_hello);
    img_challengeicon_values.add(R.drawable.actionbar_world);
}
private static ArrayList<Integer> img_challengerpic_values;
static {
    img_challengerpic_values = new ArrayList<Integer>();
    img_challengerpic_values.add(R.drawable.actionbar_look);
    img_challengerpic_values.add(R.drawable.actionbar_down);
}

we declare our adapter:

arrayAdapter adapter = new arrayAdapter(this, 
            img_challengeicon_values,
            img_challengerpic_values);

ADAPTER ACTIVITY: we extend BaseAdapter && set variables:

extends BaseAdapter {
private final Context context; 
private ArrayList<Integer> img_challengeicon_values;
private ArrayList<Integer> img_challengerpic_values;

we call constructor:

public arrayAdapter(Context context,
        ArrayList<Integer> img_challengeicon_values,
        ArrayList<Integer> img_challengerpic_values) {
this.context = context;
    this.img_challengeicon_values = img_challengeicon_values;
    this.img_challengerpic_values = img_challengerpic_values;
}

lastly we call getView, inflate layout, and assign imageviews as defined from passed variables; like so:

imgChallengeIcon.setImageResource(img_challengeicon_values.get(position));
imgChallengerPic.setImageResource(img_challengeicon_values.get(position));
2
  • 1
    Did not quite understand what you are asking for here.. Is your list empty/crashes? Commented Jun 12, 2012 at 11:43
  • That is the indication of the problem. Currently a workaround has been found that involves directly executing a query on the database; avoiding abstracting the operation into its' own class. With that calling notify data-set change on the initialized cursor effectively re-queries the data. Commented Nov 3, 2012 at 21:05

1 Answer 1

0
lstdata = (ListView) findViewById(R.id.inboxlist);
DB_listAdapter adapter = new DB_listAdapter (this,inboxdatalist);
lstdata.setAdapter(adapter);

public class DB_listAdapter extends BaseAdapter {

    private Activity activity;
    ArrayList<Object> Object_Datas;
    private static LayoutInflater inflater=null;
    ViewHolder holder;
    String strurl;


    public DB_listAdapter (Activity a,int flag, ArrayList<Object> inboxdatalist{
        // TODO Auto-generated constructor stub


        activity=a;
        this.Object_Datas=inboxdatalist;

        inflater = (LayoutInflater)activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        imageLoader=new FB_ImageLoader(activity.getApplicationContext());
    }
    @Override
    public int getCount() {
        // TODO Auto-generated method stub
        return this.Object_Datas.size();
    }

    @Override
    public Object getItem(int position) {
        // TODO Auto-generated method stub
        return position;
    }

    @Override
    public long getItemId(int position) {
        // TODO Auto-generated method stub
        return position;
    }

    public class ViewHolder{
        public TextView username;
        public TextView message;
        public ImageView image;
        public ImageButton imgaddbtn;
    }
    public View getView(int position, View convertView, ViewGroup parent) 
    {
        View v=convertView;



        if(v==null)
        {
            //LayoutInflater vi = (LayoutInflater)activity.getSystemService(myContext.LAYOUT_INFLATER_SERVICE);

            v = inflater.inflate(R.layout.listitemfb, null);

        } 

        TextView text=(TextView)v.findViewById(R.id.username);
        TextView text2=(TextView)v.findViewById(R.id.message);
        ImageView image=(ImageView)v.findViewById(R.id.avatar);





        return v;

    }

}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.