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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T17:59:20+00:00 2026-05-21T17:59:20+00:00

I have developed a very simple app that uses a custom adapter for a

  • 0

I have developed a very simple app that uses a custom adapter for a ListView.

Each row has two TextViews:

<?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="wrap_content"
    android:orientation="vertical">
    <TextView android:id="@+id/text1"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:textAppearance="?android:attr/textAppearanceMedium" />
    <TextView android:id="@+id/text2"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:textAppearance="?android:attr/textAppearanceSmall"
        android:visibility="gone" />
</LinearLayout>

The first TextView is named “text1”, and the second “text2”.
As you see, text2 is hidden (visibility=”gone”).

Also, the list has a header that only contains an EditText widget:

<?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">
    <EditText android:layout_width="fill_parent"
        android:layout_height="wrap_content" />
</LinearLayout>

Each row is represented by a very simple object named “Item” that has 2 properties (text1 and text2), and its getters/setters. Also, it has a “hasText2” method that just checks if the object has the text2 property value’s length > 0:

public class Item {
    private String text1;
    private String text2;

    public String getText1() {
        return text1;
    }
    public void setText1(String text1) {
        this.text1 = text1;
    }
    public boolean hasText2() {
        return text2.length() > 0;
    }
    public String getText2() {
        return text2;
    }
    public void setText2(String text2) {
        this.text2 = text2;
    }
}

Okay, I’ll initialize the list with just 2 items in my main app file:

Item item1 = new Item();
item1.setText1("Item 1");
item1.setText2("optional 1");
Item item2 = new Item();
item2.setText1("Item 2");
item2.setText2("");

getListView().addHeaderView(getLayoutInflater().inflate(R.layout.list_header, null), false, false);

m_items = new ArrayList<Item>();
m_adapter = new CustomListAdapter(this, R.layout.list_row, m_items);
setListAdapter(m_adapter);

m_items.add(item1);
m_items.add(item2);
m_adapter.notifyDataSetChanged();

This is the getView method of my custom adapter (that extends ArrayAdapter):

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    if (convertView == null) {
        LayoutInflater vi = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        convertView = vi.inflate(R.layout.list_row, null);
    }

    // get the two text widgets of this row layout
    TextView text1 = (TextView) convertView.findViewById(R.id.text1);
    TextView text2 = (TextView) convertView.findViewById(R.id.text2);

    // get the Item object of this row
    Item list_item = items.get(position);

    // we set the text1 property of this Item to the text1 widget
    text1.setText(list_item.getText1());

    // if this Item has a text2 (value length > 0), then set it to the text2 widget and make it visible 
    if (list_item.hasText2()) {
        text2.setText(list_item.getText2());
        text2.setVisibility(0);
    }

    return convertView;
}

So, what I want is to show the text2 widget only if the Item object has it defined (value’s length > 0).

And this is the result after running the app:

enter image description here

That’s good, it works just as I expected!! 🙂

But what if I tap the EditText of the list header? (so I force to update the list):

enter image description here

What happened here? That’s impossible. The second row has no text2 defined, and Android just has taken the text2 from the first row! Why??

The only reason I could imagine is that I cannot use rows with different visibility… but then, why Android let me do it when I just run the app? It seems to fail only when the keyboard appears (list update).

  • 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-21T17:59:20+00:00Added an answer on May 21, 2026 at 5:59 pm

    This has a problem for the exact same reason I described in notes on your previous question. The view is being recycled, so the customization performed in the clause if (list_item.hasText2()) { is permanently set on that view; even when recycled to a view for which that clause would not be true.

    In this case the following modification would probably fix the issue:

     if (list_item.hasText2()) {
        text2.setText(list_item.getText2());
        text2.setVisibility(View.VISIBLE);
     } else {
        text2.setVisibility(View.GONE);
     }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Recently, I have a developed a very simple web app for a survey. I
I have developed some custom DAO-like classes to meet some very specialized requirements for
We have developed a website that uses MVC, C#, and jQuery. In one of
I have developed a simple location aware iPhone application which is functionally working very
I have a very nice MVC Beta application developed using VS2008 on a win2008
I have developed a VB.NET WCF service that recives and sends back data. When
We have developed a webservice that sits and runs in the context of a
I have developed a framework that is used by several teams in our organisation.
I have a rather simple iPhone app consisting of numerous views containing a single,
I have some WCF RESTful services that were developed with WCF 3.5 + RESTful

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.