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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T18:25:18+00:00 2026-06-14T18:25:18+00:00

I am new to Android and I can’t find an answer to this that

  • 0

I am new to Android and I can’t find an answer to this that works.

I have the following adapter:

public class DailyDataAdapter extends ArrayAdapter<DailyData> {
    private LayoutInflater layoutInflater;
    private ArrayList<DailyData> dailyDatas;
    private boolean isUserSavedSectionDefined = false;
    private boolean isAutoSavedSectionDefined = false;
    private int resourceId;

    public DailyDataAdapter(Context context, int textViewResourceId,
            ArrayList<DailyData> dailyDatas) {
        super(context, textViewResourceId, dailyDatas);
        this.layoutInflater = (LayoutInflater) context
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        this.dailyDatas = dailyDatas;
        this.resourceId = textViewResourceId;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View dailyDataRow = convertView;

        DailyData dailyData = dailyDatas.get(position);

        if (dailyDataRow == null) {
            dailyDataRow = layoutInflater.inflate(resourceId, null);

            if (!isUserSavedSectionDefined && dailyData.isUserSaved()) {
                TextView section = (TextView) dailyDataRow
                        .findViewById(R.id.section);
                section.setText(R.string.user_saved_path);
                section.setVisibility(View.VISIBLE);
                isUserSavedSectionDefined = true;
            } else if (!isAutoSavedSectionDefined && !dailyData.isUserSaved()) {
                TextView section = (TextView) dailyDataRow
                        .findViewById(R.id.section);
                section.setText(R.string.auto_saved_path);
                section.setVisibility(View.VISIBLE);
                isAutoSavedSectionDefined = true;
            }

            TextView description = (TextView) dailyDataRow
                    .findViewById(R.id.description);
            description.setText(dailyData.getDate());
        }
        return dailyDataRow;
    }

    @Override
    public void add(DailyData newDailyData) {
        dailyDatas.add(newDailyData);
    }

    @Override
    public void addAll(Collection<? extends DailyData> newDailyDatas) {
        dailyDatas.addAll(newDailyDatas);
    }

    @Override
    public void insert(DailyData newDailyData, int index) {
        dailyDatas.add(index, newDailyData);
    }

    @Override
    public void remove(DailyData newDailyData) {
        dailyDatas.remove(newDailyData);
    }

    @Override
    public void clear() {
        dailyDatas.clear();
    }
}

Which inflates the following layout:

<?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" >

<TextView
    android:id="@+id/section"
    android:layout_width="fill_parent"
    android:layout_height="20dp"
    android:layout_marginLeft="50dp"
    android:background="@drawable/listitem_section"
    android:gravity="center"
    android:textColor="@color/white"
    android:visibility="gone"
    android:textStyle="bold" />

<TextView
    android:id="@+id/description"
    android:layout_width="fill_parent"
    android:layout_height="40dp"
    android:layout_marginLeft="50dp"
    android:background="@drawable/listitem_selector"
    android:gravity="center"
    android:singleLine="true"
    android:textColor="@color/black"
    android:textSize="@dimen/normal_text" />

<LinearLayout
    android:layout_width="fill_parent"
    android:layout_marginLeft="50dp"
    android:layout_height="1dp"
    android:background="@color/orange" >
</LinearLayout>

Now, the problem is that, if I set the content of the list associated with the adapter prior to associating it with the listView where I pretend to show the information, it works well, as so:

//Step #1
ArrayList<Data> ald = new ArrayList<Data>();
Location l = new Location("test");
Data d = new Data(l);
ald.add(d);

DailyData dd = new DailyData(false);
DailyData dd2 = new DailyData(false);
dd.setDataList(ald);
dd2.setDataList(ald);
dailyDataList.add(dd);
dailyDataList.add(dd2);

//Step #2
arrayAdapter = new DailyDataAdapter(this, R.layout.dailydata_item, dailyDataList);

But, if I associate the adapter to the listView prior to setting the content of the list (which is the pretended behaviour for the application I’m developing), nothing is shown. (Switching the Steps 1 and 2).
All the data I add is made calling the method notifyDataSetChanged afterwards.

  • 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-14T18:25:19+00:00Added an answer on June 14, 2026 at 6:25 pm

    But, if I associate the adapter to the listView prior to setting the content of the list (which is the pretended behaviour for the application I’m developing), nothing is shown. (Switching the Steps 1 and 2). All the data I add is made calling the method notifyDataSetChanged afterwards.

    Your custom ArrayAdapter will not automatically know that data has been added to dailyDataList. You need to inform it that the list has changed. You should do this in your custom adapter too, which is what ArrayAdapter does:

    @Override
    public void add(DailyData newDailyData) {
        dailyDatas.add(newDailyData);
        notifyDataSetChanged();
    }
    
    @Override
    public void addAll(Collection<? extends DailyData> newDailyDatas) {
        dailyDatas.addAll(newDailyDatas);
        notifyDataSetChanged();
    }
    
    @Override
    public void insert(DailyData newDailyData, int index) {
        dailyDatas.add(index, newDailyData);
        notifyDataSetChanged();
    }
    
    @Override
    public void remove(DailyData newDailyData) {
        dailyDatas.remove(newDailyData);
        notifyDataSetChanged();
    }
    
    @Override
    public void clear() {
        dailyDatas.clear();
        notifyDataSetChanged();
    }
    

    Now you can call arrayAdapter.add(dd); and it will automatically update the ListView for you.

    Lastly since you have overridden the majority of ArrayAdapter and don’t call the super methods, you should simply extend BaseAdapter and override the last few methods as well.

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

Sidebar

Related Questions

I'm very new to Android development and can't find the answer to this. I
I know that eclipse can do this, can Intellij via the new Android support
I have started a new Android empty project. Where can i find the graphical
This is my new android program which is a customized overlay class i can't
I'm quite new to Android development. My understanding is that you can create several
I am new to Android. can anyone tell me about Android that how can
I'm a new android developer. I've been searching for this answer all over SO
I am new to android can someone help me please, following is the code
I am new android and I would appreciate some help. I have this code:
I am new to android .can any one solve the following problem? I just

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.