0

I'm trying to reference an image inside my java class. Since Im using simple_list_item_1, Im unsure how to pull this image in from my drawable folder. Any guidance would be much appreciated. Here is my code:

public class Menu extends ListActivity {

  private static String imageView45;

  String classes[] = { "menu item 1", "menu item 2" };

  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    ImageView imgView = (ImageView) findViewById(R.id.imageView45);
    imgView.setImageResource(R.drawable.listlogobgk);

    setListAdapter(new ArrayAdapter<String>(Menu.this,
        android.R.layout.simple_list_item_1, classes));
  }

  public static String getImageView45() {
    return imageView45;
  }

  public static void setImageView45(String imageView45) {
    Menu.imageView45 = imageView45;
  }

  @Override
  protected void onListItemClick(ListView l, View v, int position, long id) {
    super.onListItemClick(l, v, position, id);
    String thisthing = classes[position];

    try {
      @SuppressWarnings("rawtypes")
      Class ourClass = Class.forName("my.package.android." + thisthing);
      Intent ourIntent = new Intent(Menu.this, ourClass);
      startActivity(ourIntent);
    } catch (ClassNotFoundException e) {
      e.printStackTrace();
    }
  }
}
3
  • Please clear your question more. What you want inside your list view? Something regarding that? Commented Mar 29, 2012 at 21:35
  • My goal is to add an image to the listview, then display my list below that. Commented Mar 30, 2012 at 22:31
  • Okay, so for this. You need to extend your ArrayAdapter with your custom adapter. Commented Mar 31, 2012 at 4:22

1 Answer 1

1

your problem can be solved by extending your own adapter from ArrayAdapter. After that, override your getView() method and inflate layout for this. Please follow this link Check out 5.0 Example for extended adaper

Hope, this will work easily!

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

1 Comment

Pleasure. If it worked then please mark question(Tick) for future ones. Thanks

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.