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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T08:21:03+00:00 2026-05-26T08:21:03+00:00

I have a listview which is filled with data form sqlitedatabase. A list-view element

  • 0

I have a listview which is filled with data form sqlitedatabase. A list-view element contains a TextView a Button and a Checkbox. Clicking on the Button shows a timepicker dialog. Accepting a time from the timepickerdialog starts an AsyncTask. There is always a new AsyncTask created when I click on the button.

Now when I click on the seventh List-Item, the first list item is updated. There might be an error with the threads.

the activity:

public class SettingsActivity extends Activity 
{
    private static final String TAG = "SettingsActivity";
    private ReminderBusAdapter busAdapter;
    private List<Reminder> reminderGoalsList;
    private static final int TIME_PICKER_DIALOG = 1;
    private static final String TIME_FORMAT = "kk:mm";
    private Calendar mCalendar;

    // view elements
    TextView tvStatus;
    ListView listViewReminder;

    @Override
    protected void onCreate(Bundle savedInstanceState) 
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.settings);

        // fetch required data reminder
        busAdapter = new ReminderBusAdapter(this);
        loadSettingsData();

        // generate view
        displayView();

        mCalendar = Calendar.getInstance();
    }

    private void loadSettingsData() 
    {
        Log.i(TAG, "loadSettingsData");
        reminderGoalsList = new ArrayList<Reminder>();
        reminderGoalsList = busAdapter.receiveReminders();

        Iterator<Reminder> iter = reminderGoalsList.iterator();
        Log.i(TAG, "iterate through all Reminders fetched from db");

        int cnt = 0;
        while (iter.hasNext()) 
        {
            cnt++;
            Log.i(TAG, cnt + "] " + iter.next().toString());
        }
    }

    private void displayView() 
    {
        Log.i(TAG, "displayView");
        tvStatus = (TextView) findViewById(R.id.settingsTextView);
        listViewReminder = (ListView) findViewById(R.id.settingsListView);
        listViewReminder.setAdapter(new SettingsAdapter(this,
                            R.layout.settings_reminder_listview, reminderGoalsList));
    }

    @Override
    protected Dialog onCreateDialog(int id, Bundle b) 
    {
        switch (id) 
        {
            case TIME_PICKER_DIALOG:
                return showTimePicker(b);
        }
        return super.onCreateDialog(id);
    }

    private Dialog showTimePicker(final Bundle b) 
    {
        TimePickerDialog timePicker = new TimePickerDialog(this, 0,
                        new TimePickerDialog.OnTimeSetListener() 
                        {
                            @Override
                            public void onTimeSet(TimePicker view, int hourOfDay, int minute) 
                            {
                                mCalendar.set(Calendar.HOUR_OF_DAY, hourOfDay);
                                mCalendar.set(Calendar.MINUTE, minute);

                                Reminder rem = (Reminder) b.get("reminder");
                                Log.i(TAG, rem.toString() + " got from adapter");

                                SimpleDateFormat dateFormat = new SimpleDateFormat(TIME_FORMAT);
                                String dateForTimeButton = dateFormat.format(mCalendar.getTime());

                                rem.setTime(dateForTimeButton);

                                new UpdateTimerByBtn().execute(new String[] 
                                                        {
                                                            rem.getTime(),
                                                            new String(Integer.toString(rem.getId())) 
                                                        });
                            }
                        }, mCalendar.get(Calendar.HOUR_OF_DAY),
                        mCalendar.get(Calendar.MINUTE), true);
        return timePicker;
    }

    class UpdateTimerByBtn extends AsyncTask<String, Integer, String> 
    {
        @Override
        protected String doInBackground(String... params) 
        {
            Log.i(TAG, "Starting AsyncTask " + "UpdateTimerByBtn new time="
                                             + params[0] + " from id= " + params[1]);

            busAdapter.updateReminder(params[0], Integer.parseInt(params[1])); 
            return "finish";
        }

        @Override
        protected void onPostExecute(String result) 
        {
            super.onPostExecute(result);
            loadSettingsData();
            displayView();
        }
    }
}

public class SettingsAdapter extends ArrayAdapter<Reminder> 
{
    protected static final String TAG = "SettingsAdapter";
    private static final int TIME_PICKER_DIALOG = 1;
    private List<Reminder> arrayListReminders;
    private int layout;
    private Activity activity;

    public SettingsAdapter(Activity activity, int layout, List<Reminder> objects) 
    {
        super(activity, layout, objects);

        this.arrayListReminders = objects;
        this.layout = layout;
        this.activity = activity;
    }

    static class ViewHolder 
    {
        private TextView listReminderTextView;
        private Button listReminderTimeButton;
        private CheckBox listReminderCheckBox;
    }

    @Override
    public View getView(int position, View convertView, android.view.ViewGroup parent) 
    {
        final Reminder rem = arrayListReminders.get(position);
        View view = convertView;
        ViewHolder viewHolder = null;

        if (view == null) 
        {
            LayoutInflater layoutInflater = (LayoutInflater) getContext()
                                    .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            view = layoutInflater.inflate(layout, parent, false);
        }

        if (view != null) 
        {
            viewHolder = new ViewHolder();
            viewHolder.listReminderTextView = (TextView) view.
                                        findViewById(R.id.list_reminder_day_textview);

            viewHolder.listReminderTimeButton = (Button) view
                                .findViewById(R.id.settings_reminder_list_time_button);

            viewHolder.listReminderCheckBox = (CheckBox) view
                                .findViewById(R.id.settings_reminder_list_checkbox);

            switch (rem.getId()) 
            {
                case 1:
                    viewHolder.listReminderTextView.setText(R.string.Mo);
                    break;
                case 2:
                    viewHolder.listReminderTextView.setText(R.string.Di);
                    break;
                case 3:
                    viewHolder.listReminderTextView.setText(R.string.Mi);
                    break;
                case 4:
                    viewHolder.listReminderTextView.setText(R.string.Do);
                    break;
                case 5:
                    viewHolder.listReminderTextView.setText(R.string.Fr);
                    break;
                case 6:
                    viewHolder.listReminderTextView.setText(R.string.Sa);
                    break;
                case 7:
                    viewHolder.listReminderTextView.setText(R.string.So);
                    break;
                default:
                    break;
            }

            viewHolder.listReminderTimeButton.setText(rem.getTime() + " " + "Uhr");

            viewHolder.listReminderTimeButton
                      .setOnClickListener(new OnClickListener() 
                        {
                            @Override
                            public void onClick(View v) 
                            {
                                Log.i(TAG, "clicked " + rem.toString());

                                Bundle bundle = new Bundle();
                                bundle.putSerializable("reminder", rem);

                                ((SettingsActivity) activity).showDialog(TIME_PICKER_DIALOG, bundle);
                            }
                        });

            viewHolder.listReminderCheckBox.setChecked(rem.isEnabled() ? true : false);
        }
        return view;
    };
}

Thanks for your help – I changed the getView Method and started debugging everything.

I think the problem is where the TimePicker Dialog is created in the Activity.

private Dialog showTimePicker(final Bundle b) 
{
    TimePickerDialog timePicker = new TimePickerDialog(this, 0,
                        new TimePickerDialog.OnTimeSetListener() 
                        {
                            @Override
                            public void onTimeSet(TimePicker view, int hourOfDay,int minute) 
                            {
                                mCalendar.set(Calendar.HOUR_OF_DAY, hourOfDay);
                                mCalendar.set(Calendar.MINUTE, minute);

                                Reminder rem = (Reminder) b.get("reminder");
                                Log.i(TAG, rem.toString() + " got from adapter");

                                SimpleDateFormat dateFormat = new SimpleDateFormat(TIME_FORMAT);
                                String dateForTimeButton = dateFormat.format(mCalendar.getTime());

                                rem.setTime(dateForTimeButton);
                                Log.i(TAG, rem.toString());
                                new UpdateTimerByBtn().execute(new String[] {
                                            rem.getTime(),
                                            new String(Integer.toString(rem.getId())) 
                                        });
                            }
                        }, mCalendar.get(Calendar.HOUR_OF_DAY)
                        , mCalendar.get(Calendar.MINUTE), true);
    return timePicker;
}

I get the required object from the Bundle. This Bunlde is final and never changes when I transfer a new Bundle from the adapter to the activity. When I click on another Button the same Dialog is shown (with the same value) and the OnTimeSetListener is executed with that final bundle. Is there a way to handle dialiogs form adapters? Should I create one Dialog for each row in the ViewHolder?

  • 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-26T08:21:03+00:00Added an answer on May 26, 2026 at 8:21 am

    Sounds like something is wrong with your getView method in the SettingsAdapter class. First of all, you’re using the ViewHolder pattern wrong. The point of the ViewHolder pattern is to avoid calling findViewById every time you used a recycled view.

    When convertView is null, you need to instantiate a new view, which is what you’re doing. The problem is that, in this case, you aren’t giving its subview’s any value… you are simply returning the view.

    A typical getView using the ViewHolder pattern looks something like this:

    public View getView(int position, View convertView,
        android.view.ViewGroup parent) {
      View view = convertView;
      ViewHolder viewHolder;
    
      if(view == null) {
        view = layoutInflater.inflate ... // instantiate new view here
    
        // note that i'm instantiating my View holder when view == null,
        // where you are instantiating it when view != null...
        viewHolder = new ViewHolder();
        viewHolder.subview1 = (TextView)view.findViewById(R.id.subview1);
        ...
        viewHolder.subviewN = (CheckBox)view.findViewById(R.id.subviewN);
        view.setTag(viewHolder);
      }
    
      viewHolder = (ViewHolder)view.getTag();
    
      // view and viewHolder are now appropriately set, so do with them what you must
    
      viewHolder.subview1.setText("blah blah");
      ...
    
      return view;
    }
    

    As I said before, you are assigning values to the view’s TextView, Button, and CheckBox only if convertView is not null… in other words, when you create a new View, you just return it as is. Maybe that would be a good place to start debugging.

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

Sidebar

Related Questions

My project is .NET/WinForms. I have a list view which is always filled with
Hallo all, I have a ListView which contains a Button in each line. The
I have a ListView which I filled in from SQL Server view called view_ListaKlientow
I have listView in which I inflate a row contain textview and button now
I have a listview NoteList which contains a method doListRefresh() to select list contents
I have a ListView which contains an ImageView and a TextView. I'm subclassing ArrayAdapter
I have a WPF ListView which repeats the data vertically. I cannot figure out
I have a listview which is populated by a SimpleCursorAdapter that is binding data
i have a ListView which contains objects bound from an collection. The representation of
I have one listview.which contain one image ,text and one button .i had creted

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.