Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1011773
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T09:50:36+00:00 2026-05-16T09:50:36+00:00

I am writing a app for android 1.5. I want to use a complex

  • 0

I am writing a app for android 1.5.
I want to use a complex listview to display my data.
I want to show a ImageView of a drawable object in my List item.

I learned from a demo:

------> listData.put("Img", listData.put("Img", R.drawable.XXX));
listData.put("Time", "100");
listItems.add(listData);

It can display correctly, however, I want to change Img at runtime, The image maybe generated at run-time, so I change the code as follow, but it falls.
Can anyone help me ? many thanks!

protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.item_list);
    itemListView = (ListView) findViewById(R.id.listview);
    ArrayList<HashMap<String, Object>> listItems = new ArrayList<HashMap<String, Object>>();
    for(int i = 0;i <XXX.size(); ++i) {
        HashMap<String, Object> listData = new HashMap<String, Object>();
--------->/*1)*/  listData.put("Img", new Drawable(XXX));
        /*2)*/  listData.put("Time", "100");
        /*3)*/  listItems.add(listData);
    }
    SimpleAdapter listItemAdapter = new SimpleAdapter(this, listItems, R.layout.listitem, new String[] { "Img", "Time"}, new int[] { R.id.listitem_img, R.id.listitem_time });
    itemListView.setAdapter(listItemAdapter);
}

listitem.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 
    android:layout_width="fill_parent" 
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_height="wrap_content" 
    android:paddingBottom="4dip"
    android:paddingLeft="12dip" 
    android:paddingRight="12dip">

    <ImageView 
        android:id="@+id/listitem_img"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:paddingTop="12dip"/>

    <TextView
        android:id="@+id/listitem_time" 
        android:layout_height="wrap_content"
        android:layout_width="wrap_content"
        android:textSize="20dip" />

</LinearLayout>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T09:50:37+00:00Added an answer on May 16, 2026 at 9:50 am

    Try this one, it has helped me.

    public class AndroidList extends ListActivity {
    
    public class MyCustomAdapter extends ArrayAdapter<String> {
    
     public MyCustomAdapter(Context context, int textViewResourceId,
       String[] objects) {
      super(context, textViewResourceId, objects);
      // TODO Auto-generated constructor stub
     }
    
     @Override
     public View getView(int position, View convertView, ViewGroup parent) {
      // TODO Auto-generated method stub
      //return super.getView(position, convertView, parent);
    
      View row = convertView;
    
      if(row==null){
       LayoutInflater inflater=getLayoutInflater();
       row=inflater.inflate(R.layout.row, parent, false);
      }
    
      TextView label=(TextView)row.findViewById(R.id.weekofday);
      label.setText(month[position]);
      ImageView icon=(ImageView)row.findViewById(R.id.icon);
    
      if (month[position]=="December"){
       icon.setImageResource(R.drawable.icon);
      }
      else{
       icon.setImageResource(R.drawable.icongray);
      }
    
      return row;
     }
    }
    
    String[] month = {
         "January", "February", "March", "April",
         "May", "June", "July", "August",
         "September", "October", "November", "December"
       };
    
      /** Called when the activity is first created. */
      @Override
      public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          //setContentView(R.layout.main);
          /*setListAdapter(new ArrayAdapter<String>(this,
            R.layout.row, R.id.weekofday, DayOfWeek));*/
          setListAdapter(new MyCustomAdapter(AndroidList.this, R.layout.row, month));
      }
    
    @Override
    protected void onListItemClick(ListView l, View v, int position, long id) {
     // TODO Auto-generated method stub
     //super.onListItemClick(l, v, position, id);
     String selection = l.getItemAtPosition(position).toString();
     Toast.makeText(this, selection, Toast.LENGTH_LONG).show();
    }
    
    }
    

    found here: http://android-er.blogspot.com/2010/06/using-convertview-in-getview-to-make.html

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am writing a app for android 1.5. I want to use a complex
I am writing an android app. I want to pass some data across the
I'm writing an android app and in it I want to have a sort
I'm writing app for android device, which is simple download manager. I want to
I am thinking to try writing an app that can use android phone to
I'm writing an android app that takes your current location and returns a list
I'm writing an app that will need to make use of Timer s, but
I'm writing an Android App and I'm looking for the fastest (In terms of
I'm writing an Android application that I want to be able to send requests
I'm currently writing an app in Android that works with the GPS. At the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.