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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T16:07:05+00:00 2026-06-16T16:07:05+00:00

I have made linear layout and add view on it, however, the view appear

  • 0

I have made linear layout and add view on it, however, the view appear twice, I dont know why it happen.Can anyone fix it??
I have problem about the adapter and I look few time and I find no strange here. But I delete the statement of addView it will not appear any View I have added before.

public View getView(int position, View convertView, ViewGroup parent) {
    // TODO Auto-generated method stub
    if(convertView == null)
    {
        LayoutInflater inflater = LayoutInflater.from(parent.getContext());
    //  inflater.inflate(R.layout. parent,false);
        convertView = inflater.inflate(R.layout.exerciseui_item,parent,false);

    }
    Exercise question = exercises.get(position);
    TextView question_view = (TextView) convertView.findViewById(R.id.exercise_question);
    String question_test = question.getOrder() + " " + question.getText()  ;
    question_view.setText(question_test);
    int answer_num = question.getAnswer().size();

    LinearLayout linear = (LinearLayout) convertView.findViewById(R.id.exercise_answer);
        ExerciseAnswer answer = question.getAnswer().get(0);
        int answer_order = answer.getOrder();
        String answer_text = answer.getText();
        String answer_final = answer_order + " " + answer_text;
        TextView answer_view = new TextView(linear.getContext());
        answer_view.setPadding(20, 5, 5, 5);
        answer_view.setTextSize(30);
        answer_view.setText(answer_final);
        linear.addView(answer_view);


    return convertView;
}

The following is the xml of the exerciseui_item

<?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"
android:id="@+id/exercise_answer" >

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

    android:textSize="13dp"
    ></TextView>
</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-16T16:07:06+00:00Added an answer on June 16, 2026 at 4:07 pm

    It sounds like view re-cycling might be behind this. Your adapter is responsible for creating the view of each item in the data set (that is the purpose of the getView method). Android, in order to conserve resources, will re-cycle views. That is why the getView method is passed a View. If the passed-in view is non-null, that means it has already been used to display data in this list.

    Thus it is the responsibility of the adapter, to “clean up” the view. In your case, that means that you have to account for the fact that you may have already dynamically added the TextView element to this view (in a previous getView call). Failure to “clean up” your view means that each time a view is re-cycled, your method will be adding yet another TextView to the layout.

    In your case, I would suggest searching the LinearLayout for the answer TextEdit. (Give this TextEdit an id so that you can find it by using findViewById()). If it already exists, then you do not need to add it.

    An other approach would be to include the 2nd TextEdit right in your XML layout. It is not clear to me why this needs to be added dynamically.

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

Sidebar

Related Questions

I have made a custom popup in an app where the layout of the
I have three buttons in my Actvity inside Linear Layout. Here i wish all
I have made custom .xml layout for ListView. Now it looks: But it isn't
I have made following relative layout in an xml file lets say add_relative_layout.xml <?xml
I have add a ViewFlipper in which has 2 linearlayout,and I have made an
I have made a graph by extending View and made graph dynamically what i
I'm just beginning Android and have gotten myself stuck. I've made a simple app/view.
I have this activity with linear layout(called myLayout) and in it there are two
i have made two view classes in first view class i am making more
Ok, i have two buttons in linear layout: <LinearLayout android:id=@+id/linearLayout1 android:layout_height=wrap_content android:layout_width=fill_parent> <Button android:id=@+id/aktiviraj_paket

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.