1

I have a custom list with image arrayadapter.I need to add some new data into that list arrayadapter.I tried to add data by

your_array_list.add("foo");
your_array_list.add("bar");

but this is not working help me to add data to list view

Here is my adapter class

public ApplicationAdapter(Context context, int textViewResourceId,
            List<ApplicationInfo> appsList) {
        super(context, textViewResourceId, appsList);
        this.context = context;
        this.appsList = appsList;
        packageManager = context.getPackageManager();
    }

    @Override
    public int getCount() {
        return ((null != appsList) ? appsList.size() : 0);
    }

    @Override
    public ApplicationInfo getItem(int position) {
        return ((null != appsList) ? appsList.get(position) : null);
    }

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

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View view = convertView;
        if (null == view) {
            LayoutInflater layoutInflater = (LayoutInflater) context
                    .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            view = layoutInflater.inflate(R.layout.snippet_list_row, null);
        }



        ApplicationInfo data = appsList.get(position);
        if (null != data) {
            TextView appName = (TextView) view.findViewById(R.id.app_name);
            TextView packageName = (TextView) view.findViewById(R.id.app_paackage);
            ImageView iconview = (ImageView) view.findViewById(R.id.app_icon);

            appName.setText(data.loadLabel(packageManager));
            packageName.setText(data.packageName);
            iconview.setImageDrawable(data.loadIcon(packageManager));
        }
        return view;
    }

Here is my activity code

applist = checkForLaunchIntent(packageManager.getInstalledApplications(PackageManager.GET_META_DATA));
        ;
        ApplicationAdapter listadaptor = new ApplicationAdapter(AllAppsActivity.this,
                    R.layout.snippet_list_row, applist);

1 Answer 1

1

If first initialization:

applist.add("foo");
ApplicationAdapter listadaptor = new ApplicationAdapter(AllAppsActivity.this,R.layout.snippet_list_row, applist);

later on if you are willing to add data:

applist.add("foo");
listadaptor.notifyDataSetChanged();

From your code i see that as a parameter of your adapter you are givin a list of objects (List<ApplicationInfo>),so instead of adding string applist.add("foo") you need to add an ApplicationInfo object something like:

ArrayList<ApplicationInfo> yourList = new ArryList<>();
yourList.add(applist);
Sign up to request clarification or add additional context in comments.

6 Comments

I am getting error notice "The method add(ApplicationInfo) in the type List<ApplicationInfo> is not applicable for the arguments (String)"
That error is shown because you have initialized a list of ApplicationInfo objects and trying to add a string to that list. Change List<ApplicationInfo> to List<String> or instead of applist.add("foo"); use applist.add(new ApplicationInfo());
please give me sample code. can u please edit your answer
@vibinreji edited. Hope it helps. But if you clarify your question to tell on what you are trying to achieve maybe we can help you on code refactoring too
thanks...but i dont want add existing package detail.i need to add dummy packages.for example my device dont have twitter app but need add it manually
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.