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

  • Home
  • SEARCH
  • 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 6134661
In Process

The Archive Base Latest Questions

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

My main layout main.xml has only a Button , a EditText and an empty

  • 0

My main layout main.xml has only a Button, a EditText and an empty ListView as below:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 

    android:layout_height="fill_parent" 
    android:layout_width="fill_parent"
>
     <LinearLayout 
         android:id="@+id/input_area"
         android:layout_width="fill_parent"
         android:layout_height="wrap_content"
         android:orientation="horizontal"

     >
         <EditText 
           android:id="@+id/input_field"
           android:layout_height="40dip"
           android:layout_width="fill_parent"
           android:layout_weight="5"
         />

         <Button
            android:id="@+id/send_btn"
            android:layout_width="60dip" 
            android:layout_height="30dip"
            android:text="@string/send"
            android:layout_weight="1"
          />

      </LinearLayout>
      <LinearLayout 
        android:id="@+id/output_area"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:background="#006633"

        android:visibility="gone"

       >
        <ListView 
            android:id="@+id/output_list"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:paddingTop="10dip"
        >

        <!-- When "send" button in above input_area is pressed, 
            text from EditText field show here programmatically as a new row of the listview-->

        </ListView>

       </LinearLayout>

</LinearLayout> 

As you see above, there are two child LinearLayout hosted by main LinearLayout.

The 1st child LinearLayout with id input_area consists of a EditText and a Button.

The 2nd child LinearLayout with id output_area is an LinearLayout with an empty ListView, AND its visibility is set to “gone“.

The feature I am going to implement is very simple, that’s in the input_area, when user input some text in the EditText field, and press the send button, then the input string should be shown in the output LinearLayout as a new row of the listview programmatically.

What I tried is the java code below:

EditText inputTxt = (EditText) findViewById(R.id.input_field);
Button sendBtn = (Button) findViewById(R.id.send_btn);

LinearLayout outputArea = findViewById(R.id.output_area);
//Updated by Saurabh
ListView lv = findViewById(R.id.output_list);
MyListAdapter mAdapter = new MyListAdapter(this, arraylist); 
//Update finished
sendBtn.setOnClickListener(new OnClickListener(){
    @Override
    public void onClick(View v){
        int visibility = outputArea.getVisibility();
        if(visibility==View.GONE)
                    // set ListView visible
            outputArea.setVisibility(View.VISIBLE);

               //get user input   
               String userInput = inputTxt.getText().toString(); // show this string in a new row of listview

                 //BUT how to dynamically add new row to the listview here???           

    }
});

But I am not sure how to add new row to the listview programmatically, anyone can help me?

By the way, I have another layout xml fiel (row.xml) which defined each row’s layout.

———————–UPDATE————————————

Each row of the list contain a icon and a text string. My list adapter and row layout are showing below:

My adapter:

private static class MyListAdapter extends BaseAdapter {
    private LayoutInflater mInflater;
    ArrayList<String> arraylist;

    public MyListAdapter(Context context, ArrayList<String> arraylist) {
        mInflater = LayoutInflater.from(context);
            this.arraylist = arraylist;
    }



    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView == null) {
            convertView = mInflater.inflate(R.layout.row, null);
            holder = new ViewHolder();
            holder.icon = (ImageView) convertView.findViewById(R.id.icon);
            holder.userInput = (TextView) convertView.findViewById(R.id.user_input);

        convertView.setTag(holder);
        } else {
        holder = (ViewHolder) convertView.getTag();
        }

        holder.icon.setImage(???);
        holder.userInput.setText(arraylist.get(position));

        return convertView;
    }

    static class ViewHolder {
        ImageView icon;
        TextView userInput;

    }
}

my list row layout:

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

        <ImageView 
             android: id="@+id/icon"
             android:layout_width="wrap_content"
         android:layout_height="wrap_content"
             >

    <TextView
        android:id="@+id/user_input" 
        android:layout_width="wrap_content"
        android:layout_height="fill_parent"
        android:textSize="10dip"/>

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

    Make a Global variable as below

    ArrayList<String> arraylist = new ArrayList<String>();
    

    On Click of send button update the adapter that you are setting on ListView by adding

    String userInput = inputTxt.getText().toString();
    arraylist.add(userInput)
    

    in adapter and then call

    adapter.notifyDataSetChanged();
    

    Update
    I updated answer in your question and in this post copy your new Adapter class and use that

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

Sidebar

Related Questions

I've got the following layout XML file: <LinearLayout xmlns:android=http://schemas.android.com/apk/res/android android:id=@+id/main_layout android:layout_width=fill_parent android:layout_height=fill_parent android:orientation=vertical> <GridView
My Android app having many buttons. My main.xml layout has three buttons. I know
I have a res/layout/main.xml including these elements and others: <some.package.MyCustomView android:id=@+id/foo (some other params)
My main.xml has two parts. In the left is a listview and in the
I called my main activity Main, and Eclipse created Main.java and res/layout/main.xml for the
I added some UI elements to the main.xml file in the res\layout folder and
My app has a main menu, and I am using a ListView to represent
Right I have a main layout defined, that has a frame, a table in
I built a simple, once screen android app - it has edittext boxes for
I have a reasonably complex layout problem: I would like to have a main

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.