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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T06:38:03+00:00 2026-06-17T06:38:03+00:00

this is how I add items to the ListView: public class ServersAdapter extends ArrayAdapter<String>

  • 0

this is how I add items to the ListView:

public class ServersAdapter extends ArrayAdapter<String> {

    public ServersAdapter(Context context, int resource, int textViewResourceId, String[] servers) {
        super(context, resource, textViewResourceId, servers);
        Log.d("noc", "ServersAdapterin: ");
        // TODO Auto-generated constructor stub
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        Log.d("noc", "getView: ");

        LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        View row  = inflater.inflate(R.layout.servers_list, parent, false);

        Log.d("noc", "inflate: ");
        //datasource = new ServersDataSource(getContext());
        datasource.open();
        //servir list
        Log.d("noc", "ServersDataSource: ");
        Server[] servers = datasource.getAllServers();
        ImageView iv = (ImageView) row.findViewById(R.id.imageView1);
        TextView tv = (TextView) row.findViewById(R.id.textView1);

        Log.d("noc", "setText: ");
        if (servers.length > 0) {
            tv.setText(servers[position].getTitle());
            Log.d("noc", "getTitle: ");

            Log.d("noc", "servers[position].getTitle()-==================: "+ servers[position].getTitle());
            if (servers[position].getEnabled() < 1) {
                iv.setImageResource(R.drawable.ic_server_status_red);
            } else {
                iv.setImageResource(R.drawable.ic_server_status_green);
            }
        }
        return row;

    }
}

this is the onCreate:

......
try {

        Log.d("noc", "need to delete this: ");
        datasource = new ServersDataSource(this);
        datasource.open();
        //servir list
        Log.d("noc", "servir list: ");
        //String[] servers = new String[10];
        //servir list
        Log.d("noc", "ServersDataSource: ");
        String[] servers = new String[10];


        Log.d("noc", "end need to delete this");
        ArrayAdapter<Server> adapter = new ServersAdapter(this, android.R.layout.simple_list_item_1, R.id.textView1, servers);
        setListAdapter(adapter);
    } catch (Exception e) {
        Log.d("noc", "error (ArrayAdapter): " + e.toString());
    }

I am unable to clear a ListView from all of its content (I’m trying to empty it). I have been trying to do so like so:

ArrayAdapter<Server> adapter = (ArrayAdapter<Server>) getListAdapter();
Server server = null;
switch (view.getId()) {
    case R.id.add:
        // Save the new server to the database
        // server_id, "title", "url", "ip", enabled, "services", fetch_interval
        server = datasource.createServer(1, "title of the server", "url of the server", "ip of the server", 1, "services of the server", 1);
        adapter.add(server);
        break;
    case R.id.delete:
        Log.d("noc", "delete ");
        if (getListAdapter().getCount() > 0) {
            datasource.emptyServersTable();
            Log.d("noc", "clear ");
            adapter.clear();
            Log.d("noc", "after clear ");

        }
        break;
    }
    Log.d("noc", "notifyDataSetChanged");
    adapter.notifyDataSetChanged();

and this is the output when click “delete”:

01-11 23:41:54.210: D/noc(14898): delete 
01-11 23:41:54.210: D/noc(14898): emptyServersTable: 
01-11 23:41:54.230: D/noc(14898): clear 
01-11 23:41:54.230: D/AndroidRuntime(14898): Shutting down VM
01-11 23:41:54.230: W/dalvikvm(14898): threadid=1: thread exiting with uncaught exception (group=0x4140e2a0)
01-11 23:41:54.230: E/AndroidRuntime(14898): FATAL EXCEPTION: main
01-11 23:41:54.230: E/AndroidRuntime(14898): java.lang.IllegalStateException: Could not execute method of the activity
01-11 23:41:54.230: E/AndroidRuntime(14898):    at android.view.View$1.onClick(View.java:3699)
01-11 23:41:54.230: E/AndroidRuntime(14898):    at android.view.View.performClick(View.java:4223)
01-11 23:41:54.230: E/AndroidRuntime(14898):    at android.view.View$PerformClick.run(View.java:17275)
01-11 23:41:54.230: E/AndroidRuntime(14898):    at android.os.Handler.handleCallback(Handler.java:615)
01-11 23:41:54.230: E/AndroidRuntime(14898):    at android.os.Handler.dispatchMessage(Handler.java:92)
01-11 23:41:54.230: E/AndroidRuntime(14898):    at android.os.Looper.loop(Looper.java:137)
01-11 23:41:54.230: E/AndroidRuntime(14898):    at android.app.ActivityThread.main(ActivityThread.java:4898)
01-11 23:41:54.230: E/AndroidRuntime(14898):    at java.lang.reflect.Method.invokeNative(Native Method)
01-11 23:41:54.230: E/AndroidRuntime(14898):    at java.lang.reflect.Method.invoke(Method.java:511)
01-11 23:41:54.230: E/AndroidRuntime(14898):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1008)
01-11 23:41:54.230: E/AndroidRuntime(14898):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:775)
01-11 23:41:54.230: E/AndroidRuntime(14898):    at dalvik.system.NativeStart.main(Native Method)
01-11 23:41:54.230: E/AndroidRuntime(14898): Caused by: java.lang.reflect.InvocationTargetException
01-11 23:41:54.230: E/AndroidRuntime(14898):    at java.lang.reflect.Method.invokeNative(Native Method)
01-11 23:41:54.230: E/AndroidRuntime(14898):    at java.lang.reflect.Method.invoke(Method.java:511)
01-11 23:41:54.230: E/AndroidRuntime(14898):    at android.view.View$1.onClick(View.java:3694)
01-11 23:41:54.230: E/AndroidRuntime(14898):    ... 11 more
01-11 23:41:54.230: E/AndroidRuntime(14898): Caused by: java.lang.UnsupportedOperationException
01-11 23:41:54.230: E/AndroidRuntime(14898):    at java.util.AbstractList.remove(AbstractList.java:638)
01-11 23:41:54.230: E/AndroidRuntime(14898):    at java.util.AbstractList$SimpleListIterator.remove(AbstractList.java:75)
01-11 23:41:54.230: E/AndroidRuntime(14898):    at java.util.AbstractList.removeRange(AbstractList.java:658)
01-11 23:41:54.230: E/AndroidRuntime(14898):    at java.util.AbstractList.clear(AbstractList.java:466)
01-11 23:41:54.230: E/AndroidRuntime(14898):    at android.widget.ArrayAdapter.clear(ArrayAdapter.java:258)
01-11 23:41:54.230: E/AndroidRuntime(14898):    at com.wr.noc.ServersStatus.onClick(ServersStatus.java:91)
01-11 23:41:54.230: E/AndroidRuntime(14898):    ... 14 more

so what is the problem. is there another way to do so?

  • 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-17T06:38:04+00:00Added an answer on June 17, 2026 at 6:38 am

    You should try to override the clear() method in the ServersAdapter class and add a call to the clear() method of your ArrayList if you have one. If your data is loaded into views from an array just empty it.

    Looking at your code I think the concerned one is servers.

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

Sidebar

Related Questions

I'm trying to add items to an arraylist using this class template: public class
I want to add items to the listview underneath the edittext. This works perfectly.
I have the following code: SPList list = web.Lists[this.ListName]; SPListItem item = list.Items.Add(); now
Getting this error when try to add an item to my repositories/context: Collection has
I'm trying to filter my ListView which is populated with this ArrayAdapter: package me.alxandr.android.mymir.adapters;
I am trying to add dynamic textview to listview items.textviews can be of 1-2
I have changed this class extends with Acitvity and before that it was extends
I am trying to programatically add items to a ListView in WPF. I have
My overall goal is to add fake/unbound items to a listview control (for final
I'm using this tutorial to add a Login Item to my application. Most of

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.