Home > DeveloperSection > Forums > How to set image in listview android?
Allen Scott

Total Post:41

Points:289
Posted on    November-15-2014 3:28 AM

 Android Android Listview  Image View 
Ratings:


 1 Reply(s)
 729  View(s)
Rate this:
set image in listview android


Anurag Sharma
Anurag Sharma

Total Post:40

Points:280
Posted on    November-15-2014 6:57 AM

public class MainActivity extends Activity {

  ListView list;

  String[] webString = {    "Google Plus",      "Twitter",      "Windows",      "Bing",      "Itunes",      "Wordpress",    "Drupal"

  } ;

Integer[] imageId = {

      R.drawable.google,

      R.drawable.twitter,

      R.drawable.windows,

      R.drawable.bing,

      R.drawable.itunes,

      R.drawable.wordpress,

      R.drawable.drupal  };

@Override

  protected void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_main);

    CustomList adapter = new

        CustomList(MainActivity.this, webString, imageId);

    list=(ListView)findViewById(R.id.listview);

        list.setAdapter(adapter);

        list.setOnItemClickListener(new AdapterView.OnItemClickListener() {

                @Override

                public void onItemClick(AdapterView<?> parent, View view,

                                        int position, long id) {

                    Toast.makeText(MainActivity.this, "You Clicked at " +webString[+ position], Toast.LENGTH_SHORT).show();

                }

            });

  }}




Don't want to miss updates? Please click the below button!

Follow MindStick