Reputation: 23
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);
Upvotes: 1
Views: 572
Reputation: 4480
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);
Upvotes: 1