-3

Ok so i sucsessfully gotten my names from my database, and now i've stored them in the array result[], and at the end of the code i've written return result; now my question, how do i get the names from my result[] to appear in a listview? note: i do not want to have the connecting to mysql database on the same class as my listview one.

How would i go about doing this?

I also wish to know how i would go about making a custom listview with the names and a picture on the side. Also if you could tell me how i would go about adding pictures to listviews aswell, that'd be great :) i'm going to be using bmp, retriving them from database as byte[] and then convert them to bmp.

note: fairly new to java and android development

  • 1
    Possible duplicate is http://stackoverflow.com/questions/8166497/custom-adapter-for-list-view You can use instead of TextView to ImageView for your images. – okarakose Aug 05 '14 at 07:26
  • 1
    to the downvoters: downvotes should be explained so that the user can understand why his question is getting downvoted and eventually improve it: @user3807261 Your question clearly show that you did not any search effort or even tried to solve your problem thus is being downvoted. Your question is too broad and you clearly lack any knowledge to solve your problem. StackOverflow's goal is to help people solve a specific problem, not giving ready to use code. This said you probably want to read the android documentation that explain how would you bind data to a listview really well. – Antonio E. Aug 05 '14 at 07:30
  • have you googled what you are asking?because there are lots of tutorial regarding listview and customizing its view – Ker p pag Aug 05 '14 at 07:30
  • @AntonioE. I would like to give you 1000 for it. Because, downvoting has become a fashion. – Nabin Aug 05 '14 at 07:35
  • i'm aware there are a lot of tutorials about this.. but i hate reading.. i'd prefer to have a GOOD video tutorial.. but it's non existant.. or atleast very hard 2 find – user3807261 Aug 05 '14 at 09:14

1 Answers1

0

You can find a lot of examples on internet. A simple example would be:

ListView listView = (ListView) findViewById(R.id.listOne);

    String[] name={"HELLO","THIS","IS","NABIN"};
    String[] phone={"12","24","36","48"};

    ArrayList<HashMap<String,String>> obj= new ArrayList<HashMap<String,String>>();

    for(int i=0;i<name.length;i++){
        HashMap<String,String> toFill = new HashMap<String,String>();
        toFill.put("name", name[i]);
        toFill.put("phone", phone[i]);
        obj.add(toFill);
    }

    //to define adapter

    ListAdapter adapter = new SimpleAdapter(MainActivity.this, obj, R.layout.contact, new String[] {"name", "phone"},new int[] {R.id.etName,R.id.etPhone});
    listView.setAdapter(adapter);

Edited:

For images to display:(Considering your images are in drawable folder)

You have to make a custom adapter

And for imageView of custom adapter do the following:

String imageName = ......// get text from your array which would be the name of image.
int resID = getResources().getIdentifier(imageName , "drawable", getPackageName());

ImageView imageView = (ImageView) findViewById(R.id.image);
imageView.setImageResource(resId);
Nabin
  • 11,216
  • 8
  • 63
  • 98