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 6124189
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T16:06:15+00:00 2026-05-23T16:06:15+00:00

I am trying to create a homescreen widget using the 3.1 SDK. I followed

  • 0

I am trying to create a homescreen widget using the 3.1 SDK. I followed the StackWidget tutorial. and changed the StackView to ListView.
I want to add an image and text to each row in my list, and these are loaded at runtime.

I use this code in my WidgetProvider.java class

public RemoteViews getViewAt(int position) {

    Bitmap bitmap = ((BitmapDrawable)mWidgetItems.get(position).getImage());

    RemoteViews image = new RemoteViews(mContext.getPackageName(), R.layout.widget_item);      
    image.setImageViewBitmap(R.id.widget_image, bitmap );

    RemoteViews text = new RemoteViews(mContext.getPackageName(), R.layout.widget_item); 
    text.setTextViewText(R.id.widget_text, mWidgetItems.get(position).getText());

    RemoteViews layout = new RemoteViews(mContext.getPackageName(), R.layout.widget_item);

    Bundle extras = new Bundle();
    extras.putInt(StackWidgetProvider.EXTRA_ITEM, position);
    Intent fillInIntent = new Intent();
    fillInIntent.putExtras(extras);

    layout.setOnClickFillInIntent(R.id.widget_item, fillInIntent);

    return layout;
}

All of this works correctly when I use StackView, but changing to ListView messes up everything. The result is this

enter image description here

Only one view can be returned. So, if I add the following code, this problem occurs, if I don’t add it, then the content of the list is empty.

layout.addView(R.id.widget_item, image);
layout.addView(R.id.widget_item, text);

How else do I add multple views to a widget?
Why does this work for StackView but not ListView?
and how do I rectify this?

Any help is greatly appreciated.

EDIT

widget_item.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/widget_item"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="center_vertical">
<ImageView
    android:id="@+id/widget_image"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:padding="10dp"/>
<TextView
    android:id="@+id/widget_text"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:padding="20dp"
    android:layout_weight="1"
    android:textColor="#000000"/>       
</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-23T16:06:16+00:00Added an answer on May 23, 2026 at 4:06 pm

    You rectify this by inflating the right layout from the outset. R.layout.widget_image should already have whatever stuff you have in R.layout.widget_image and R.layout.widget_item.

    This will be:

    • faster to execute (fewer instructions to achieve same visual end)
    • less Java code
    • less layout code (one layout file versus three)
    • easier to maintain layout code (you can use the visual editor in Eclipse to maintain your list rows better)

    And, as an extra bonus, it should work for any supported AdapterView-based app widget.

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

Sidebar

Related Questions

I am trying to create an application that has a background image with widget
I'm trying create a bot which automatically likes Facebook posts. Using Mechanize I can
Ok so I am trying create a login script, here I am using PHP5
Trying to create several layers of folders at once C:\pie\applepie\recipies\ without using several different
hi I'm trying create chat using node.js I see example in http://chat.nodejs.org/ I have
Trying to create an iPhone app (Objective-C) for my school. I want it to
While Trying to create a Menu to SubMenu using InsertMenuItem: MENUITEMINFO mii = {
I am trying create the image enlargement effect when you hover your mouse over
I am trying to create an WiFi widget for ICS supported devices. In ICS
I am trying create a table and add this table into tablecell (table inside

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.