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

The Archive Base Latest Questions

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

Hi I created a list view and Item,The item contains 2 linear layouts and

  • 0

Hi I created a list view and Item,The item contains 2 linear layouts and i want to visible these layout on the ,depends on values ,i tried to do this in getview of adapter but its not working prperly my code shows below
Item.xml

<LinearLayout android:id="@+id/LinearLayout00"
    android:layout_width="fill_parent"
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:gravity="fill_horizontal"
    android:hapticFeedbackEnabled="true"
    android:layout_gravity="fill_horizontal"
    android:alwaysDrawnWithCache="true" android:background="#ccc"
    android:layout_height="wrap_content">
    <LinearLayout android:id="@+id/LinearLayout01"
        android:layout_width="fill_parent" android:orientation="horizontal"
        android:gravity="fill_horizontal"
        android:hapticFeedbackEnabled="true"
        android:layout_gravity="fill_horizontal"
        android:alwaysDrawnWithCache="true" android:background="#ccc"
        android:layout_height="wrap_content">
        <ImageView android:id="@+id/image"
            android:layout_width="50dip" android:layout_height="50dip"
            android:src="@drawable/stub" android:scaleType="centerCrop"
            android:background="#000000" android:layout_margin="5dip" />
        <LinearLayout android:id="@+id/LinearLayout01"
            android:layout_height="wrap_content"
            android:layout_gravity="fill_horizontal"
            android:layout_width="fill_parent" android:orientation="vertical"
            android:paddingLeft="5dip" android:paddingRight="5dip">
            <TextView android:id="@+id/text" android:text="Username"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_weight="1" android:layout_gravity="left|center_vertical"
                android:textColor="#111" />
            <TextView android:layout_height="wrap_content"
                android:id="@+id/Story" android:text="Story"
                android:layout_width="fill_parent" android:textColor="#111"
                android:textColorHighlight="#06f" android:textStyle="bold"
                android:typeface="sans" android:textSize="15dip" />
            <TextView android:layout_height="wrap_content"
                android:id="@+id/Time" android:text="12 hours ago"
                android:layout_width="fill_parent" android:textColor="#333"
                android:textSize="11dip" android:paddingBottom="5dip" />
            <TextView android:layout_height="wrap_content"
                android:id="@+id/Pid" android:visibility="gone"
                android:layout_width="fill_parent" android:textSize="0dip" />
        </LinearLayout>
    </LinearLayout>
    <LinearLayout android:id="@+id/LinearLayout02"
        android:layout_height="wrap_content"
        android:layout_gravity="fill_horizontal"
        android:layout_width="fill_parent" android:orientation="vertical"
        android:visibility="gone" android:paddingLeft="5dip"

        android:paddingRight="5dip">
        <TextView android:layout_height="wrap_content"
            android:id="@+id/follows" android:text="12 hours ago"
            android:layout_width="fill_parent" android:textColor="#333"
            android:textSize="11dip" android:paddingBottom="5dip" />
        <TextView android:layout_height="wrap_content"
            android:id="@+id/followData" android:text="Click"
            android:clickable="true" android:layout_width="fill_parent"
            android:textColor="#333" android:textSize="11dip"
            android:paddingBottom="5dip" />
    </LinearLayout>
</LinearLayout>

java file

public View getView(int position, View convertView, ViewGroup parent) {

    View vi=convertView;
    ViewHolder holder;

    Post o=listItems1.get(position);

    if(convertView==null){

        vi = inflater.inflate(R.layout.item, null);
        holder=new ViewHolder();

        LinearLayout ly1=(LinearLayout)vi.findViewById(R.id.LinearLayout01);
        LinearLayout ly2=(LinearLayout)vi.findViewById(R.id.LinearLayout02);
        if(o.getPostType().equals("0"))
        {
            ly1.setVisibility(View.VISIBLE);
            ly2.setVisibility(View.GONE);
        }
        else
        {
            ly2.setVisibility(View.VISIBLE);
            ly1.setVisibility(View.GONE);
        }
        //ly.setVisibility(View.VISIBLE);

        holder.text=(TextView)vi.findViewById(R.id.text);
        holder.story=(TextView)vi.findViewById(R.id.Story);
        holder.timeSpan=(TextView)vi.findViewById(R.id.Time);
        holder.image=(ImageView)vi.findViewById(R.id.image);
        holder.pid=(TextView)vi.findViewById(R.id.Pid);

        holder.follows=(TextView)vi.findViewById(R.id.follows);
        holder.followsData=(TextView)vi.findViewById(R.id.followData);

        vi.setTag(holder);

    }
    else
        holder=(ViewHolder)vi.getTag();

    holder.text.setText(o.getUserName());
    holder.story.setText(Html.fromHtml(o.getStory()));
    holder.timeSpan.setText(o.getTime());
    holder.pid.setText(""+o.getPid());

    holder.image.setTag(listItemsUrl.get(position).toString());
    imageLoader.DisplayImage(listItemsUrl.get(position).toString(), activity, holder.image);

    return vi;

}

please help me

Regard Augustine

  • 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-21T21:31:59+00:00Added an answer on May 21, 2026 at 9:31 pm

    You need to set the visibility of those views regardless of the value of the convertView parameter.
    Since it is recycled, might (and most likely does) hold other value than the one given to it right now.

    So you should remove the part

    LinearLayout ly1=(LinearLayout)vi.findViewById(R.id.LinearLayout01);
    LinearLayout ly2=(LinearLayout)vi.findViewById(R.id.LinearLayout02);
    if(o.getPostType().equals("0"))
    {
        ly1.setVisibility(View.VISIBLE);
        ly2.setVisibility(View.GONE);
    }
    else
    {
        ly2.setVisibility(View.VISIBLE);
        ly1.setVisibility(View.GONE);
    }
    

    from the if clause, and place after it.

    You should also take a look at Romain Guy’s series about Android layout tricks, to see how your layout could be less a waste of views.

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

Sidebar

Related Questions

I want to use a list view and I have created my own layout
I have created a dialog which contains a list view. The onclicklistener for the
I have created a ListView which contains a list of items. Each item in
In my application i have a listView. each item of the list view contains
I'm creating a ListActivity. In each list item I have a View I've created
I have a custom list View that contains 7 text views..I have created a
I have create a listview of Contact numbers , the list item contains the
I have created a list view that displays the names and dates of items
I have created a custom list view, each row has it's own custom selector,
I have created navigaton view using Sencha touch 2. Navigation view has list component

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.