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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T08:24:25+00:00 2026-06-08T08:24:25+00:00

I am programming my first Android App and am facing a problem :( I

  • 0

I am programming my first Android App and am facing a problem 🙁 I am using Eclipse and the app is intended to run from Android 4.0.3.

I have a tab actionbar on the top of the view, constisting of 4 tabs. Three of them have the same structure: a radiogroup with two radiobuttons and a listView under it. These tabs are based on the same data and will be used to filter the data. The text of the radioButton depends on the tab and will further filter the data.

The last tab has a completely different layout and function.

I have made two fragment and two layouts (one for the first three, and one for the last tab). The first fragment is managing the radiogroup an the listview. I also have an adapter to set the data model, depending on which tab and button is selected. But somehow I just can’t get it to work correctly. The of the radiobuttons doesn’t refresh and the list is only showing first time the activity is loaded. No exception is thrown.

Is my approach wrong?

Here is the my main activity:

    @Override
public void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);
    setContentView(R.layout.list_main);

    appContext = getApplicationContext();


    dataholder = (P1DataHolder) getIntent().getSerializableExtra(
            "data"); //Hold all the data

    final ActionBar mainBar = getActionBar();
    mainBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
    mainBar.setDisplayOptions(0, ActionBar.DISPLAY_SHOW_TITLE);

    // create the fragments with the name of parent tab
    Fragment aFragment = new ListFragment(
            MyApplication.TAB_A);
    Fragment bFragment = new ListFragment(
            MyApplication.TAB_B);
    Fragment cFragment = new ListFragment(
            MyApplication.TAB_C);
    Fragment settingFragment = new P1SettingFragment();

    // Fragment A
    ActionBar.Tab tabA = mainBar.newTab().setText(
            MyApplication.TAB_A);
    tabA.setTabListener(new TabsListener(aFragment));

    // Fragment B
    ActionBar.Tab tabB = mainBar.newTab().setText(
            MyApplication.TAB_B);
    tabB.setTabListener(new TabsListener(bFragment));

    // Fragment C
    ActionBar.Tab tabC = mainBar.newTab().setText(
            MyApplication.TAB_C);
    tabC.setTabListener(new TabsListener(cFragment));

    // Settings
    ActionBar.Tab tabSetting = mainBar.newTab().setText(
            MyApplication.TAB_SETTING);
    tabSetting.setTabListener(new TabsListener(settingFragment));

    // Adding Tabs to actionbar
    mainBar.addTab(tabA);
    mainBar.addTab(tabB);
    mainBar.addTab(tabC);
    mainBar.addTab(tabSetting);

}

Edit: code of the frame

public class ListFragment extends Fragment {

private ArrayList<Recipe> listAll;
private ArrayList<Recipe> listNotCookedYet;
private CustomListView ls;
private SectionComposerAdapter adapter;
private Activity parent;
private String tabTag; // Tab state from Parent
private View view;
private SegmentedRadioGroup segmentText;
private RadioButton rbAll;
private RadioButton rbNotCookedYet;


public ListFragment(String tabTag, ArrayList<Recipe> listAll, ArrayList<Recipe> listNTY) {
    this.tabTag = tabTag;
    this.listAll = listAll;
    this.listNotCookedYet = listNTY;
}

public String getTabTag(){
    return this.tabTag;
}

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
        Bundle savedInstanceState) {

    // Inflate the layout for this fragment
    view = inflater.inflate(R.layout.list_with_section, container,
            false);
    parent = getActivity();

    // get Elements
    segmentText = (SegmentedRadioGroup) view
            .findViewById(R.id.segment_text);
    rbAll = (RadioButton) view.findViewById(R.id.button_list_all);
    rbNotCookedYet = (RadioButton) view
            .findViewById(R.id.button_list_notcookedyet);

    // Set Content
    if (parent != null && parent instanceof ListMainActivity) {

        ListDataHolder holder = ((ListMainActivity) parent)
                .getDataHolder();

        adapter = new SectionComposerAdapter(parent, holder);
        adapter.getCount();
        initialize(adapter);

        System.out.println("ANZAHL ALL: " + listAll.size());
        System.out.println("ANZAHL UNCOOKED: " + listNotCookedYet.size());

        //The default text is "all (*)" and "not cooked yet (*)"
        rbAll.setText(rbAll.getText().toString()
                .replace("*", listAll.size() + ""));
        rbNotCookedYet.setText(rbNotCookedYet.getText().toString()
                .replace("*", listNotCookedYet.size() + ""));

        segmentText
                .setOnCheckedChangeListener(new OnCheckedChangeListener() {

                    @Override
                    public void onCheckedChanged(RadioGroup group,
                            int checkedId) {

                        if (rbAll.getId() == checkedId) {
                            adapter.setDataModel(tabTag, true);
                            System.out.println("CHECKED: All");

                        }

                        else if (rbNotCookedYet.getId() == checkedId) {
                            adapter.setDataModel(tabTag, false);
                            System.out.println("CHECKED: Not Yet");
                        }


                    }
                });

    }
    return view;
}

@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);

}

private void initialize(SectionComposerAdapter adapter) {
    ls = (CustomListView) view
            .findViewById(R.id.list_services);
    ls.setPinnedHeaderView(LayoutInflater.from(parent).inflate(
            R.layout.item_composer_header, ls, false));
    ls.setAdapter(adapter);
    ls.setOnItemClickListener(new OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view,
                int position, long id) {

            Intent intent = new Intent(view.getContext(),
                    RecipeActivity.class);
            startActivityForResult(intent, 0);

        }
    });
}

The ListDataHolder has sectioned the data alphabetically and holds them as separate Arraylist for each tab and each radiobutton selection (so there are 6 arraylists).

And here is my adapter:

public class SectionComposerAdapter extends CustomListAdapter {

private Activity activity;
private ListDataHolder dataholder;
private static LayoutInflater inflater = null;
private ImageLoader imageLoader;
private List<Pair<String, ArrayList<Recipe>>> data;

public SectionComposerAdapter(Activity a, ListDataHolder holder) {
    activity = a;
    this.dataholder = holder;
    inflater = (LayoutInflater) activity
            .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    imageLoader = new ImageLoader(activity.getApplicationContext());
    data = dataholder.getAllData(dataholder.getAZRecipeAll());
}

public void setDataModel(String tab, boolean all) {
    if (MyApplication.TAB_A.equals(tab)) {
        if (all) {
            data = dataholder.getAllData(dataholder.getAZRecipeAll());
        } else {
            data = dataholder.getAllData(dataholder
                    .getAZRecipeNotCookedYet());
        }
    } else if (MyApplication.TAB_B.equals(tab)) {
        if (all) {
            data = dataholder.getAllData(dataholder.getMeatRecipeAll());
        } else {
            data = dataholder.getAllData(dataholder
                    .getMeatRecipeNotCookedYet());
        }
    } else if (MyApplication.TAB_C.equals(tab)) {
        if (all) {
            data = dataholder
                    .getAllData(dataholder.getVegetarianRecipeAll());
        } else {
            data = dataholder.getAllData(dataholder
                    .getVegetarianRecipeNotCookedYet());
        }
    }


}

@Override
public int getCount() {
    int res = 0;
    for (int i = 0; i < data.size(); i++) {
        res += data.get(i).second.size();
    }
    return res;
}

@Override
public Recipe getItem(int position) {
    int c = 0;
    for (int i = 0; i < data.size(); i++) {
        if (position >= c && position < c + data.get(i).second.size()) {
            return data.get(i).second.get(position - c);
        }
        c += data.get(i).second.size();
    }
    return null;
}

@Override
public long getItemId(int position) {
    return position;
}

@Override
protected void onNextPageRequested(int page) {
}

@Override
protected void bindSectionHeader(View view, int position,
        boolean displaySectionHeader) {
    if (displaySectionHeader) {
        view.findViewById(R.id.list_section_header).setVisibility(
                View.VISIBLE);
        TextView lSectionTitle = (TextView) view
                .findViewById(R.id.list_section_header);
        lSectionTitle
                .setText(getSections()[getSectionForPosition(position)]);
    } else {
        TextView lSectionTitle = (TextView) view
                .findViewById(R.id.list_section_header);
        lSectionTitle
                .setText(getSections()[getSectionForPosition(position)]);
        view.findViewById(R.id.list_section_header)
                .setVisibility(View.GONE);
    }
}

@Override
public View getAmazingView(int position, View convertView, ViewGroup parent) {
    View vi = convertView;
    if (vi == null)
        vi = inflater.inflate(R.layout.list_row, null);

    TextView recipename = (TextView) vi.findViewById(R.id.recipe_name);
    TextView recipevip = (TextView) vi.findViewById(R.id.recipe_fav_mark);
    ImageView thumb_image = (ImageView) vi.findViewById(R.id.list_image);

    Recipe recipe = new Recipe();
    recipe = getItem(position);

    // Setting all values in listview
    recipename.setText(recipe.getTitle);
    recipevip.setText(recipe.isFav() ? "FAV" : "");
    imageLoader.DisplayImage(recipe.getImage_thumbnail(), thumb_image);

    return vi;
}

@Override
public void configurePinnedHeader(View header, int position, int alpha) {
    TextView lSectionHeader = (TextView) header;
    lSectionHeader.setText(getSections()[getSectionForPosition(position)]);
    // lSectionHeader.setBackgroundColor(alpha << 24 | (0xbbffbb));
    // lSectionHeader.setTextColor(alpha << 24 | (0x000000));
}

@Override
public int getPositionForSection(int section) {
    if (section < 0)
        section = 0;
    if (section >= data.size())
        section = data.size() - 1;
    int c = 0;
    for (int i = 0; i < data.size(); i++) {
        if (section == i) {
            return c;
        }
        c += data.get(i).second.size();
    }
    return 0;
}

@Override
public int getSectionForPosition(int position) {
    int c = 0;
    for (int i = 0; i < data.size(); i++) {
        if (position >= c && position < c + data.get(i).second.size()) {
            return i;
        }
        c += data.get(i).second.size();
    }
    return -1;
}

@Override
public String[] getSections() {
    String[] res = new String[data.size()];
    for (int i = 0; i < data.size(); i++) {
        res[i] = data.get(i).first;
    }
    return res;
}

The list works fine without the tabs and radiobuttons. The listener is also working fine, I see the change of tabs and radiobutton in the logs. I just can’t get them working together correctly.

Thank you in advance and I am hoping for some tips 😉

Diana

  • 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-08T08:24:26+00:00Added an answer on June 8, 2026 at 8:24 am

    Erm…how embarassing, I was spending two day searching for the problem in the code, when the answer is so simple. I have null data returned from an url for the other tabs.

    Sorry!

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

Sidebar

Related Questions

I'm programming my very first GUI app in Java using the Swing framework. I've
I am new to Eclipse and Android programming in general but I have been
Recently started programming Android Java (Eclipse), Im trying to make a simple reader app
I am programming on an android app, and I have a program with a
Okay, first, I'm a noob at android programming. I have taken some Java, but
The android-app I'm programming is going to have a database of products, say 150-250
i'm programming for Android 2.1.Could you help me with the following problem? I have
I'm new to android programming (writing my first app now) and I need some
again i have got a problem with socket programming in Android. My Problem is
I am programming the first android tutorial in eclipse, and when compiling this code:

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.