I have no idea why I’m getting it on this line of code (where the arrow is)
protected void onListItemClick(ListView l, View v, int position, long id) {
---> App selection = (App) l.getItemAtPosition(position);
Custom ArrayAdapter:
public class MyCustomAdapter extends ArrayAdapter<String>{
private ArrayList<String> myarr = new ArrayList<String>();
private LayoutInflater inflater;
//objects = array of whatever you want to add to the list
public MyCustomAdapter(Context context,
int textViewResourceId, List<String> objects) {
super(context, textViewResourceId, objects);
myarr = (ArrayList<String>) objects;
inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View row = convertView;
if(row==null){
row=inflater.inflate(R.layout.list_row, parent,false);
}
((TextView)row.findViewById(R.id.rowtextview)).setText(myarr.get(position));
return row;
}
This is the arrayadapter that does the work. I’m assuming the problem is in here.
You must have stored
Stringin yourListView. It gives the exception because it cannot castStringtoAppEDIT
The objects in your
myarrare displayed in yourListView. Those objects are allStrings. In the line where you get exception you are trying to convert theStringatpositionto anApp. It cannot do that so you get the exception. So try this:EDIT2
Change
myarrtoChange the following line:
Add
Appclass: