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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T17:03:47+00:00 2026-05-23T17:03:47+00:00

I’m trying to set a Listview under some other Widgets (Buttons, editText, etc). I

  • 0

I’m trying to set a Listview under some other Widgets (Buttons, editText, etc). I don’t want to use another activity for the listview. After reading some I found How can I implement a ListView without ListActivity? (use only Activity) and I tried to do it, ending up with:
Here is my main.xml:

<LinearLayout android:id="@+id/relativeLayout1"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:orientation="vertical">
<TextView ...[some code].../>
<EditText ...[some code].../>
<ImageButton ...[some code].../>
<Chronometer ..[some code]..../>
<ListView android:id="@+id/listView1" android:layout_height="wrap_content"
    android:layout_width="fill_parent"></ListView>

here is my onCreate:

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    button1 = (ImageButton) findViewById(R.id.button1);
    mChronometer = (Chronometer) findViewById(R.id.chronometer1);
    editText1 = (EditText) findViewById(R.id.editText1);
    ListView lv = (ListView) findViewById(R.id.listView1);
    String[] listword = new String[] {"Hello","World","Foo","Bar"};
    lv.setAdapter(new ArrayAdapter<String>(this, R.layout.list_item, listword));
    }

and here is list_item.xml

<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="10dp"
android:textSize="16sp" >
</TextView>

When I debug in my physical device, the application simply stays all black. If I comment out the lines of onCreate() that involve the list, the application works (obviously without the listview).
Any ideas what might be wrong?

  • 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-23T17:03:47+00:00Added an answer on May 23, 2026 at 5:03 pm

    I actually have an app with a listview below some TextViews and above two buttons, let me grab my code!

    Here’s my activity with listview below the textviews and above the buttons (with quite a bit removed for brevity):

    public class BNYDirectoryResults extends Activity{
    
        public static String[] stuff;
        ListView list;
        BNYAdapter adapter;
    
        /** Called when the activity is first created. */
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.resultscreen);
    
            TextView headDisplay = (TextView)findViewById(R.id.results);
            TextView headCount = (TextView)findViewById(R.id.resultsTotal);
            TextView headPages = (TextView)findViewById(R.id.pages);
    
          //Set up the results list, see BNYAdapter
            list = (ListView)findViewById(R.id.list);
            adapter = new BNYAdapter (this, BNYDirectory.ReturnResults);
            list.setAdapter(adapter);
    
          //Sets up header information (pages, total results)
            //Just some stuff to change the TextViews
    
    
          //Passes EmployeeID and Phone Number to AND opens the details page
            list.setOnItemClickListener(new OnItemClickListener(){
                public void onItemClick(AdapterView<?> parent, View view, int position, long id){
                    String EID = BNYDirectory.ReturnResults[position][0];
                    String phoneNumber = BNYDirectory.ReturnResults[position][2];
    
                    BNYDirectoryTransaction.doDetails(EID, phoneNumber);
                    Intent i = new Intent(view.getContext(), BNYDirectoryDetails.class);
                    startActivity(i);
    
                }
            });
        }
    }
    

    Here’s the XML file for it:

        <TextView
            android:id="@+id/results"
            android:text="Name"
            android:gravity="center"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1" android:textStyle="bold"/>
        <TextView
            android:id="@+id/resultsTotal"
            android:text="Phone"
            android:gravity="center"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1" android:textStyle="bold"/>
        <TextView
            android:id="@+id/pages"
            android:text="AIM"
            android:gravity="center"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1" android:textStyle="bold"/>
      </LinearLayout>
    
      <LinearLayout
          android:layout_width="fill_parent"
          android:layout_height="wrap_content"
          android:orientation="horizontal">
    
        <TextView
            android:id="@+id/name"
            android:text="Name"
            android:gravity="center"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1" />
        <TextView
            android:id="@+id/phone"
            android:text="Phone"
            android:gravity="center"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1" />
        <TextView
            android:id="@+id/aim"
            android:text="AIM"
            android:gravity="center"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1" />
        <TextView
            android:id="@+id/dept"
            android:text="Dept"
            android:gravity="center"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1" />
      </LinearLayout>
    
      <ListView
          android:id="@+id/list"
          android:layout_width="fill_parent"
          android:layout_height="fill_parent" 
          android:layout_weight="1"/>
    
      <LinearLayout
          android:layout_width="fill_parent"
          android:layout_height="wrap_content"
          android:orientation="horizontal">
    
        <Button
            android:id="@+id/prevButton"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content" 
            android:text="Previous" 
            android:layout_weight="1"/>
        <Button
            android:id="@+id/nextButton"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content" 
            android:text="Next" 
            android:layout_weight="1"/>
    
      </LinearLayout>
    </LinearLayout>
    

    and here’s the custom adapter for the list:

    import android.app.Activity;
    import android.content.Context;
    import android.view.LayoutInflater;
    import android.view.View;
    import android.view.ViewGroup;
    import android.widget.BaseAdapter;
    import android.widget.TextView;
    
    public class BNYAdapter extends BaseAdapter {
    
        private Activity activity;
        private String[][] results;
        private static LayoutInflater inflater=null;
    
        public BNYAdapter(Activity a, String[][]info) {
            activity = a;
            results = info;
            inflater = (LayoutInflater)activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        }
    
        public int getCount() {
            return results.length;
        }
    
        public Object getItem(int position) {
            return position;
        }
    
        public long getItemId(int position) {
            return position;
        }
    
        public static class ViewHolder{
            public TextView name;
            public TextView phone;
            public TextView aim;
            public TextView dept;
        }
    
        public View getView(int position, View convertView, ViewGroup parent) {
            View vi=convertView;
            ViewHolder holder;
            if(convertView==null){
                vi = inflater.inflate(R.layout.item, null);
                holder=new ViewHolder();
                holder.name=(TextView)vi.findViewById(R.id.nameItem);
                holder.phone=(TextView)vi.findViewById(R.id.phoneItem);
                holder.aim=(TextView)vi.findViewById(R.id.aimItem);
                holder.dept=(TextView)vi.findViewById(R.id.deptItem);
                vi.setTag(holder);
            }
            else
                holder=(ViewHolder)vi.getTag();
    
            holder.name.setText(BNYDirectory.ReturnResults[position][1]);
            holder.phone.setText(BNYDirectory.ReturnResults[position][2]);
            holder.aim.setText(BNYDirectory.ReturnResults[position][3]);
            holder.dept.setText(BNYDirectory.ReturnResults[position][4]);
            return vi;
        }
    
    }
    

    and all together that makes a page like Look, a list with other stuff around it!

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

Sidebar

Related Questions

I am trying to understand how to use SyndicationItem to display feed which is
I want use html5's new tag to play a wav file (currently only supported
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this

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.