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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T20:47:14+00:00 2026-06-12T20:47:14+00:00

I am trying to build a custom Listview , with an image to the

  • 0

I am trying to build a custom Listview, with an image to the right , main text and sub text. The main problem is I don’t get any errors and a blank view shows up. I can click on it, but I don’t see any content on my ListView. My code:

    public class MenuScreen extends Activity  {            
            TextView maintext, subtext;
            ImageView icon ;

                    private static final String [] menuitems = {"Availability","Messages","Greetings","Address Book","Calls","Settings"};
                    private static final int [] menu_icons = {R.drawable.menu_availability,R.drawable.menu_messages,R.drawable.menu_greetings,R.drawable.menu_contacts,R.drawable.menu_calls,R.drawable.menu_settings}; 
                    private static String [] submenu_items = {"1","2","3","4","5","6"};
                    @Override
                        protected void onCreate(Bundle savedInstanceState) {
                            // TODO Auto-generated method stub
                            super.onCreate(savedInstanceState);
                            setContentView(R.layout.menulogin_main);
                            maintext = (TextView)findViewById(R.id.tvMainText);
                            subtext = (TextView)findViewById(R.id.tvSubText);
                            icon = (ImageView)findViewById(R.id.iicon);

                            List<HashMap<String,String>> aList = new ArrayList<HashMap<String,String>>();
                             for(int i=0;i<6;i++){
                                    HashMap<String, String> hm = new HashMap<String,String>();
                                    hm.put("tvMainText", "MainText : " + menuitems[i]);
                                    hm.put("tvSubText","SubText : " + submenu_items[i]);
                                    hm.put("iicon", Integer.toString(menu_icons[i]) );
                                    aList.add(hm);
                                }

                             String[] from = { "iicon","tvMainText","tvSubText" };

                             int[] to = { R.id.iicon , R.id.tvMainText, R.id.tvSubText} ;

                             SimpleAdapter adapter = new SimpleAdapter(getBaseContext(), aList, R.layout.menulogin_main, from, to);

                               // Getting a reference to listview of main.xml layout file
                               ListView listView = ( ListView ) findViewById(R.id.listmenu);

                               // Setting the adapter to the listView
                               listView.setAdapter(adapter);
                            listView.setOnItemClickListener(new OnItemClickListener() {

                                public void onItemClick(AdapterView<?> listview, View view,
                                        int position, long id) {
                                    switch(position){

                                    case 0 :
                                        Intent avail = new Intent(MenuScreen.this,Availability.class);
                                        startActivity(avail);

                                    break;
                                    }

                                }
                            });

                    }

                }

Layout file for the ListView, menulogin_main:

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
         android:background="@drawable/background"
        android:orientation="vertical" >


        <ListView
            android:id="@+id/listmenu"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" >

        </ListView>

    </LinearLayout>

Layout file for the row, menulogin:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >


        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content" >

            <ImageView
                android:id="@+id/iicon"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_margin="10dp"
                android:src="@drawable/logon_image" />

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:orientation="vertical" >

                <TextView
                    android:id="@+id/tvMainText"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginBottom="5dp"
                    android:layout_marginTop="5dp"
                    android:text="MAIN TEXT"
                    android:textAppearance="?android:attr/textAppearanceLarge" />

                <TextView
                    android:id="@+id/tvSubText"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="SUB TEXT"
                    android:textAppearance="?android:attr/textAppearanceMedium" />
            </LinearLayout>
        </LinearLayout>

    </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-06-12T20:47:15+00:00Added an answer on June 12, 2026 at 8:47 pm

    That is probably happening because of the layout file you use. You have the same layout file for the activity layout(R.layout.menulogin_main), but also you use the same layout file for the ListViews adapter. Now, you either have the ListView(with the id R.id.listmenu) and the row views(R.id.iicon , R.id.tvMainText, R.id.tvSubText) in the same layout(R.layout.menulogin_main) and the ListView covers those views or you intended to use another layout for the ListView row and not R.layout.menulogin_main(but this will probably throw an exception).

    You should have a special layout file designed for the ListView‘s row which contains only the desired views.

    Edit:
    Layout file for menu_login:

    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent" >
    
        <ImageView
            android:id="@+id/iicon"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_margin="10dp"
            android:src="@drawable/ic_launcher" />
    
        <TextView
            android:id="@+id/tvSubText"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:layout_toRightOf="@id/iicon"
            android:text="SUB TEXT"
            android:textAppearance="?android:attr/textAppearanceMedium" />
    
        <TextView
            android:id="@+id/tvMainText"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_above="@id/tvSubText"
            android:layout_alignParentTop="true"
            android:layout_marginBottom="5dp"
            android:layout_marginTop="5dp"
            android:layout_toRightOf="@id/iicon"
            android:text="MAIN TEXT"
            android:textAppearance="?android:attr/textAppearanceLarge" />
    
    </RelativeLayout>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to build a custom clock view in Android. See image http://twitpic.com/1devk7 So
I'm trying to build a custom segue, but i can't seem to get the
I'm trying to build a custom configuration and with some reason, I can't get
I am trying to build a custom adapter for my app, who's main screen
I am trying to build site with custom script. I have problem with allowing
I'm fairly new to Android, and am trying to build a custom component in
I am trying to build a simple custom editor in the Eclipse environment. To
I'm trying to build a menu using a UItableView with Custom cells which have
I'm trying to build a custom function for ajax but the output is null
i am trying to build an custom validator with symfony2 but something strange happens:

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.