How to set image in listview android?

set image in listview android
Last updated:11/15/2014 6:57:47 AM

1 Answers

Anurag Sharma
Anurag Sharma

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();
                }
            });
  }}



Answer