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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T02:04:19+00:00 2026-06-16T02:04:19+00:00

I need to output data from lines cm1 and cm2 in a ListView, every

  • 0

I need to output data from lines cm1 and cm2 in a ListView, every time when I press the button. Line should be shown in various TextView.

Code TEST.java:

public String cm1;
public String cm2;

public class TEST extends Activity {
@Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        MyList = (ListView) this.findViewById(R.id.listStrings);
         setListAdapter();

        // button
        Button setup = (Button) this.findViewById(R.id.send);
        setup.setOnClickListener(new View.OnClickListener() {
        public void onClick(View view) {
        cm1 = "cm1text";
        cm2 = "cm2text";
        //xxxx
        }
        });
}

// adapter
private void setListAdapter() {
    ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
    R.layout.row //idknow what im must writehere to set cm1 string to cm1text tv
    List.setAdapter(adapter);
    }

Code TEST.xml:

<?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="vertical" >

<ListView
    android:id="@+id/listStrings"
    android:layout_width="wrap_content"
    android:layout_height="0dp"
    android:layout_weight="1" />

    <Button
        android:id="@+id/send"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Send" />
</LinearLayout>

Code row.xml:

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

<TextView
    android:id="@+id/cm1tv"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" />

<TextView
    android:id="@+id/cm2tv"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" />

</RelativeLayout>

Should look ListView after 2 clicks:

cm1
cm2
cm1
cm2
  • 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-16T02:04:21+00:00Added an answer on June 16, 2026 at 2:04 am

    Maybe what you should/can do is have this;

    String cm = cm1 + "\n" + cm2
    

    Which should output;
    cm1
    cm2

    Then you change the xml to just have one textview and the adapter code as follows;

    ArrayList<String> listItems = new ArrayList<String>();
    ArrayAdapter<String> aa = new ArrayAdapter<String>(this, R.layout.row, R.id.textViewCM, listItems);
    yourListView.setAdapter(aa);
    

    Then, whenever you press the button;

    // ...code to initialise/change cm
    listItems.add(cm);
    aa.notifyDataSetChanged(); // notifies listView to update it's view
    

    That should do what you’re after unless you’ve got to have the two individual textViews, in which case, you’ll need to write a custom adapter, I’ve done a bit of a tutorial on my website if you follow that link.

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

Sidebar

Related Questions

Problem I have some pages that need dynamic data from website to generate output
I have a C# MVC application which I need to output the following data
I need to get some external data to form an output file name in
I need to output a file in the format of a Word document from
I need to output the lines of a file where the first column's values
I have data with a best fit line draw. I need to draw two
I have a need to transfer large streams of data from a web service.
I need to pull data from a text file, sort it, then save over
I need some help in transforming an input data which is from reading a
What I need to achieve is to import data from a text file that

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.