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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T10:31:53+00:00 2026-06-09T10:31:53+00:00

I have sectioned custom ListView that contains RadioButton on each items. When a Dialog

  • 0

I have sectioned custom ListView that contains RadioButton on each items. When a Dialog open, the RadioButton that has been checked (selected) becomes unchecked (unselected). I don’t know what might cause this happens…

Here is my code listing.

ArrayList<Item> items = new ArrayList<Item>();
private EntryAdapter adapter;
private SharedPreferences preference;
private int usernameKe;

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

    preference = getSharedPreferences("preference", Context.MODE_PRIVATE);

    items.add(new SectionItem("Pengaturan PIN"));
    items.add(new EntryItem("Ubah PIN",
            "Masukkan PIN Anda yang baru di sini"));

    items.add(new SectionItem("Pilihan Nomor Tujuan Pengiriman"));
    items.add(new EntryItem("IM3", "085741222225"));
    items.add(new EntryItem("AS", "082372423333"));
    items.add(new EntryItem("XL", "081915348000"));
    items.add(new EntryItem("3", "08986903333"));

    items.add(new SectionItem("Pengelolaan User ID"));
    items.add(new EntryItem("Tambah ID", "Masukkan User ID baru"));
    int jumlahUsername = Integer.parseInt(preference.getString(
            "jumlah_userid", "0"));
    if (jumlahUsername >= 1) {
        for (int i = 1; i <= jumlahUsername; i++) {
            String nilaiDitampilkan = preference.getString("u" + i, "");
            items.add(new EntryItem(nilaiDitampilkan, ""));
        }
    }
    // Toast.makeText(this, jumlahUsername + "", Toast.LENGTH_SHORT).show();

    int nomorTerpilih = preference.getInt("nomor", 0);

    adapter = new EntryAdapter(QuickPrefsActivity.this, this, items,
            nomorTerpilih);
    setListAdapter(adapter);
}

@Override
protected void onListItemClick(ListView l, View v, int selectedPosition,
        long id) {

    if (!items.get(selectedPosition).isSection()) {
        RadioButton radioButton = (RadioButton) v
                .findViewById(selectedPosition);

        ((MyApplication) getApplication())
                .setSomeVariable(selectedPosition);
        Editor editorPage = preference.edit();
        editorPage.putInt("nomor", selectedPosition);
        editorPage.commit();

        switch (selectedPosition) {
        case 1:
            showDialog(0);
            break;
        case 3:
            radioButton.setChecked(true);
            break;
        case 4:
            radioButton.setChecked(true);
            break;
        case 5:
            radioButton.setChecked(true);
            break;
        case 6:
            radioButton.setChecked(true);
            break;
        case 8:
            showDialog(1);
        }
        adapter.notifyDataSetInvalidated();
    }
    super.onListItemClick(l, v, selectedPosition, id);
}

@Override
protected Dialog onCreateDialog(int id) {
    Dialog dialog = null;
    LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    final View layout = inflater.inflate(R.layout.ubah_pin_dialog,
            (ViewGroup) findViewById(R.id.ubahPinLayout));
    final TextView textView = (TextView) layout
            .findViewById(R.id.upahPinTextView);
    textView.setGravity(Gravity.CENTER);
    final EditText editText = (EditText) layout
            .findViewById(R.id.pinEditText);
    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setView(layout);
    if (id == 0) {
        String pin = preference.getString("PIN", "");
        textView.setText("Masukkan PIN Anda yang baru di sini");
        editText.setText(pin);
        editText.setInputType(InputType.TYPE_CLASS_NUMBER);
        builder.setTitle("Ubah PIN");
        builder.setPositiveButton("Ubah",
                new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface arg0, int arg1) {
                        String pinDisimpan = editText.getText().toString();
                        if (pinDisimpan.length() == 4) {
                            SharedPreferences pinPreference = getSharedPreferences(
                                    "preference", Context.MODE_PRIVATE);
                            Editor editorPage = pinPreference.edit();
                            editorPage.putString("PIN",
                                    pinDisimpan.toString());
                            editorPage.commit();
                        } else {
                            Toast.makeText(getApplicationContext(),
                                    "GAGAL: PIN tidak valid",
                                    Toast.LENGTH_SHORT).show();
                        }
                    }
                });
        builder.setNegativeButton("Batal",
                new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface arg0, int arg1) {
                    }
                });
        final AlertDialog pinDialog = builder.create();
        dialog = pinDialog;
    } else {
        textView.setText("Masukkan username Anda yang baru di sini");
        editText.setText("");
        builder.setView(layout);
        builder.setTitle("User ID");
        builder.setPositiveButton("Tambah",
                new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface arg0, int arg1) {
                        usernameKe = items.size() - 8;
                        String size = String.valueOf(usernameKe);
                        String nilaiDisimpan = editText.getText()
                                .toString();
                        preference = getSharedPreferences("preference",
                                Context.MODE_PRIVATE);
                        Editor editorPage = preference.edit();
                        editorPage.putString("u" + size, nilaiDisimpan);
                        editorPage.putString("jumlah_userid", size);
                        editorPage.commit();

                        Toast.makeText(getApplicationContext(),
                                Integer.parseInt(size) + "",
                                Toast.LENGTH_SHORT).show();
                        items.add(new EntryItem(nilaiDisimpan, ""));
                        adapter.notifyDataSetChanged();
                    }
                });
        builder.setNegativeButton("Batal",
                new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface arg0, int arg1) {
                    }
                });
        final AlertDialog pinDialog = builder.create();
        dialog = pinDialog;
    }
    return dialog;
}
  • 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-09T10:31:57+00:00Added an answer on June 9, 2026 at 10:31 am

    OK i think i know the solution. It is because i put notifyDataSetInvalidate outside the switch case (listView items). It would work for all cases. Therefore the code should be changed like below.

    switch (selectedPosition) {
        case 1:
            showDialog(0);
            break;
        case 3:
            radioButton.setChecked(true);
        adapter.notifyDataSetInvalidated();
            break;
        case 4:
            radioButton.setChecked(true);
        adapter.notifyDataSetInvalidated();
            break;
        case 5:
            radioButton.setChecked(true);
        adapter.notifyDataSetInvalidated();
            break;
        case 6:
            radioButton.setChecked(true);
        adapter.notifyDataSetInvalidated();
            break;
        case 8:
            showDialog(1);
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a ListView with some custom sections in it. Each section has it's
HI Guyz i have created a sectioned custom listview using baseadapter its working fine
I have a section of a website that has three divs next to each
I have a MyProject.config file that contains ConnectionStrings, AppSettings, and custom sections. I don't
I have a web application with a custom configuration section. That section contains information
I have created an editable UITableView that supports several custom UITableViewCells of my own
I have a table view with three sections. The first section contains custom cells
I have a problem with my Android listview. My list uses a custom arrayadapter,
I want to have a listview with a custom adatper, extends ArrayAdapter, where Type
I have a generic list of custom objects and would like to reduce that

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.