さて、私はSOを少し検索しましたが、うまくいく答えが得られないようです。これは近いですが、リストの最後の項目を削除し、最後の値を削除するとクラッシュします。リスト行の内側にあるボタンで、リストのコンテンツに基づいてアクションを実行し、その行をリストから削除したいだけです。ありがとうございました!
public class CitrusListAdapter extends ArrayAdapter<CitrusList>
{
//Globals
Context context;
int layoutResourceId;
ArrayList<CitrusList> data = null;
//Create the list item row
public CitrusListAdapter(Context context, int layoutResourceId, ArrayList<CitrusList> listItems)
{
super(context, layoutResourceId, listItems);
this.layoutResourceId = layoutResourceId;
this.context = context;
this.data = listItems;
}
//Expand and place items for List View onto calling page in ListView
@Override
public View getView(final int position, View convertView, ViewGroup parent)
{
View row = convertView;
CitrusListHolder holder = null;
if(row == null)
{
LayoutInflater inflater = ( (Activity) context).getLayoutInflater();
row = inflater.inflate(layoutResourceId, parent, false);
holder = new CitrusListHolder();
//holder.txtTitle = (TextView)row.findViewById(R.id.CitrusListTitle);
holder.colorSpinner = (Spinner)row.findViewById(R.id.color_spinner);
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(getContext(),
R.array.colors_array, android.R.layout.simple_spinner_item);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
holder.colorSpinner.setAdapter(adapter);
holder.textureSpinner = (Spinner)row.findViewById(R.id.texture_spinner);
ArrayAdapter<CharSequence> texture_adapter = ArrayAdapter.createFromResource(getContext(),
R.array.texture_array, android.R.layout.simple_spinner_item);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
holder.textureSpinner.setAdapter(texture_adapter);
holder.soliditySpinner = (Spinner)row.findViewById(R.id.solidity_spinner);
ArrayAdapter<CharSequence> solidity_adapter = ArrayAdapter.createFromResource(getContext(),
R.array.solidity_array, android.R.layout.simple_spinner_item);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
holder.soliditySpinner.setAdapter(solidity_adapter);
Button rateButton = (Button) row.findViewById(R.id.rate_button);
rateButton.setTag(position);
rateButton.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View v)
{
Integer index = (Integer) v.getTag();
data.remove(index.intValue());
notifyDataSetChanged();
}
});
row.setTag(holder);
}
else
{
holder = (CitrusListHolder)row.getTag();
}
CitrusList SingleLine = data.get(position);
//holder.txtTitle.setText(SingleLine.title);
return row;
}
//Stores the values of the items in the list view
static class CitrusListHolder
{
//TextView txtTitle;
Spinner colorSpinner;
Spinner textureSpinner;
Spinner soliditySpinner;
}
}