HOW TO SET IMAGE IN LISTVIEW ANDROID?

Allen Scott

Total Post:46

Points:324
Posted by  Allen Scott
 1236  View(s)
Ratings:
Rate this:
set image in listview android
  1. Anurag Sharma

    Post:40

    Points:280
    Re: How to set image in listview android?

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



      Modified On Apr-06-2018 06:17:30 AM

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!