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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T11:56:23+00:00 2026-05-30T11:56:23+00:00

This is my code: how to write the java code display the one by

  • 0

This is my code: how to write the java code display the one by one textview ,for example click the submit button display the text view and store And next time click the same button display the next text view and store the data.how write this type of java code,I have a main .xml file

public class XMLRWActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button submit_btn =  (Button) findViewById (R.id.submit_btn);
final EditText textbox = (EditText) findViewById (R.id.first_text);
final TextView newtext = (TextView) findViewById (R.id.read_text);

submit_btn.setOnClickListener(new View.OnClickListener() {
    public void onClick(View v) {
            byte[] readinfo = new byte[160];
            String FILENAME = "first_file";
        FileOutputStream mystream;
    try {
        mystream = openFileOutput (FILENAME, Context.MODE_PRIVATE);
        String variabletowrite = textbox.getText().toString();

        mystream.write(variabletowrite.getBytes());
        mystream.close();
        FileInputStream readstream = openFileInput (FILENAME);
        readstream.read(readinfo);
        newtext.setText(new String(readinfo));


        readstream.close();
    } catch (FileNotFoundException e) {
    e.printStackTrace();
    } catch (IOException e) {
    e.printStackTrace();
    }
    }
   });
   }
 }

This is a main.xml file

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:weightSum="1">
<TextView  
android:layout_width="fill_parent" 
android:layout_height="wrap_content" 
android:text="@string/hello"
/>
<EditText android:id="@+id/first_text"
 android:layout_width="match_parent"
android:layout_height="wrap_content">
<requestFocus></requestFocus>
</EditText>
<Button android:layout_height="wrap_content" 
android:text="Submit"     
android:id="@+id/submit_btn" 
 android:layout_width="match_parent" />

<TextView
android:id="@+id/read_text1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="TextView1"
android:textAppearance="?android:attr/textAppearanceLarge" ></TextView>
<TextView
android:id="@+id/read_text2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="TextView2"
android:textAppearance="?android:attr/textAppearanceLarge" ></TextView>
<TextView
android:id="@+id/read_text3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="TextView3"
android:textAppearance="?android:attr/textAppearanceLarge" >

 </TextView>
</LinearLayout>

This is a storage permission in manifest file

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" > </uses-permission>
  • 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-30T11:56:24+00:00Added an answer on May 30, 2026 at 11:56 am

    You can use listview

    public class MainActivity extends Activity implements OnClickListener, OnItemSelectedListener
    {
    /** Called when the activity is first created. */

    private static String[] data = new String[]
    { "aaaa", "bbbbbb", "ccccc", "ddddd", "eeee", "ffffff", "gggggg ", "hhhhhhhhhhh", "iiiiiiiiii", "jjjjjjjjjjj" };
    
    private ListView lvDynamic;
    private ViewAdapter viewAdapter;
    
    private class ViewAdapter extends BaseAdapter
    {
        private Context context;
        private List textIdList = new ArrayList();
    
        @Override
        public View getView(int position, View convertView, ViewGroup parent)
        {
            String inflater = Context.LAYOUT_INFLATER_SERVICE;
            LayoutInflater layoutInflater = (LayoutInflater) context.getSystemService(inflater);
            LinearLayout linearLayout = null;
            if (textIdList.get(position) instanceof String)
            {
                linearLayout = (LinearLayout) layoutInflater.inflate(R.layout.text, null);
                TextView textView = ((TextView) linearLayout.findViewById(R.id.textview));
                textView.setText(String.valueOf(textIdList.get(position)));
            }
            return linearLayout;
        }
    
        public ViewAdapter(Context context)
        {
            this.context = context;
        }
    
        @Override
        public int getCount()
        {
            return textIdList.size();
        }
    
        @Override
        public Object getItem(int position)
        {
            return textIdList.get(position);
        }
    
        public void addText(String text)
        {
            textIdList.add(text);
            notifyDataSetChanged();
        }
    
    
        @Override
        public long getItemId(int position)
        {
            return position;
        }
    }
    
    
    @Override
    public void onItemSelected(AdapterView<?> parent, View view, int position,
            long id)
    {
        id = position;
    
    }
    
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
    
        lvDynamic = (ListView) findViewById(R.id.lvDynamic);
        Button btnAddText = (Button) findViewById(R.id.btnAddText);
    
        btnAddText.setOnClickListener(this);
    
        viewAdapter = new ViewAdapter(this);
        lvDynamic.setAdapter(viewAdapter);
        lvDynamic.setOnItemSelectedListener(this);
    }
    
    
    public void onClick(View v)
    {
        // TODO Auto-generated method stub
        int randomNum = new Random().nextInt(data.length);
        viewAdapter.addText(data[randomNum]);
    }
    
    @Override
    public void onNothingSelected(AdapterView<?> arg0)
    {
        // TODO Auto-generated method stub
    
    }
    

    }

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

Sidebar

Related Questions

I have this code to write to a file, it works perfect but I
would someone please write this code: this.Loaded += (s, e) => this.loaded = true;
How can I write this code more cleanly/concisely? /// <summary> /// Creates a set
Is there a better way to write this code? I want to show a
When I write code like this in VS 2008: .h struct Patterns { string
Many beginning programmers write code like this: sub copy_file ($$) { my $from =
This code does not seem to compile, I just need to write something to
I have problem with this code: file = tempfile.TemporaryFile(mode='wrb') file.write(base64.b64decode(data)) file.flush() os.fsync(file) # file.seek(0)
I have this code to update users data, but I can't write the for
Im using this code: $(this).css('backgroundcolor', localStorage.getItem('bgColorr') + !important;); When i write: alert( localStorage.getItem('bgColorr') +

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.