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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T17:37:01+00:00 2026-05-23T17:37:01+00:00

I have custom list_row : <LinearLayout xmlns:android=http://schemas.android.com/apk/res/android android:orientation=horizontal android:layout_width=match_parent android:orientation=horizontal android:layout_width=match_parent android:layout_height=wrap_content android:baselineAligned=false> <Button

  • 0

I have custom list_row :

    <LinearLayout
 xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal" android:layout_width="match_parent"
android:orientation="horizontal" android:layout_width="match_parent"
android:layout_height="wrap_content" android:baselineAligned="false">
<Button android:layout_width="30dip" android:layout_marginTop="7dip" android:gravity="right"
android:id="@+id/delete" android:layout_height="30dip" android:background="@drawable/delete"
android:layout_gravity="top"></Button>
<TextView android:textSize="20dip"
android:text="TextView" android:id="@+id/tavsiye" android:layout_marginTop="10dip" 
android:layout_gravity="top" android:layout_width="wrap_content" 
android:layout_height="wrap_content"></TextView>
</LinearLayout>

I have a ListView like that:

<ListView 
        android:id="@+id/tavsiyeler"
        android:layout_height="300dip"
        android:layout_width="170dip"
        android:fastScrollEnabled="true"
        android:scrollbars="vertical"/>

and a custom adapter which extends ArrayAdapter :

public class HekimTavsiyeleriAdapter extends ArrayAdapter<String> {


private Context context;
private int resource;
private ArrayList<String> tavsiyeler;


public HekimTavsiyeleriAdapter(Context context, int resource,
         ArrayList<String> objects) {
    super(context, resource,  objects);
    this.context=context;
    this.resource=resource;
    this.tavsiyeler=objects;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
    View v = convertView;
    if (v == null) {
        LayoutInflater vi = (LayoutInflater)this.context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        v = vi.inflate(this.resource, null);
    }

    if (this.tavsiyeler.size()!=0) {
            TextView tavsiye = (TextView) v.findViewById(R.id.tavsiye);
            Button but= (Button) v.findViewById(R.id.delete);

            if (tavsiye != null) {
                String st=this.tavsiyeler.get(position);
                tavsiye.setText(st);     
            }
            if( but!=null){
                but.setId(position);
                but.setOnClickListener(new AdapterView.OnClickListener() {

                    @Override
                    public void onClick(View v) {
                        int id=v.getId();       
                        tavsiyeler.remove(id);
                        notifyDataSetChanged();

                    }                           
                  });

            }

    }
    return v;
}

I am creating adapter and fill the list like that :

    eklenecekTavsiyeler=new ArrayList<String>();
    adapter= new HekimTavsiyeleriAdapter(context,
            R.layout.hekim_tavsiyeleri_row, eklenecekTavsiyeler);

    ListView tavsiyelerListesi = (ListView)findViewById(R.id.tavsiyeler);
    tavsiyelerListesi.setAdapter(adapter);

And adding new items like that:

this.adapter.add(<some-string>);
    this.adapter.notifyDataSetChanged();

and my list view is seen like that:

http://imageshack.us/photo/my-images/97/listir.jpg/

Here is my question:

I am adding new items to the list. I have fixed height for the list. When I fill the list until all height is occupied, then I add one new item to the list which requires scrolling becasue overflow in list height. The last item I added gets wrong id and when I pressed the cross button, it removes wrong item. However, when the list is not overflowed, everything works fine. After overflow, the ids of buttons are set wrongly (seems randomly). By the way, for setting the button’s id, I am using getView’s position argument.

Thanks in advance.

  • 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-23T17:37:01+00:00Added an answer on May 23, 2026 at 5:37 pm

    I am afraid that you have flaw in the code.
    You have to stop calling but.setId(). With this you are overriding internal id of the view which is the value of R.id.delete. Probably you meant to use but.setTag() / but.getTag()?

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

Sidebar

Related Questions

I use the following main.xml for my app. <?xml version=1.0 encoding=utf-8?> <LinearLayout xmlns:android=http://schemas.android.com/apk/res/android android:layout_width=fill_parent
Basically, I have a custom ListView in which each item looks like: <LinearLayout> <Table>
I have List of items. I'm using custom adapter (Android 1.5). Everything works perfectly,
I have list view with custom row layout (list_row.xml) that contains CheckBox element: <TableLayout
I have defined a custom Sharepoint list for special attributes related to a software
I have a custom class Contact . I am trying to bind a List<Contact>
I have a DataGridView with its datasource set to a generic list of custom
I have custom coded several enterprise applications for mid to large organizations to use
I have custom errors configured in my web.config, but IIS 6.0 is returning the
Can you have custom client-side javascript Validation for standard ASP.NET Web Form Validators? For

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.