我有一个在活动中使用自定义适配器填充的gridview,并且我希望您在另一个gridview中的另一个活动中按下目标项目。android将项目添加到arraylist from arraylist
private static class MyAdapter extends BaseAdapter
{
static List<Item> items = new ArrayList<Item>();
private LayoutInflater inflater;
public MyAdapter(Context context)
{
inflater = LayoutInflater.from(context);
items.add(new Item("Restaurante Arsenal", R.drawable.arsenal));
items.add(new Item("Restaurante The Grill", R.drawable.grill));
items.add(new Item("Rte Las Delicias", R.drawable.delicias));
items.add(new Item("Restaurante Europa", R.drawable.logo_restaurante_europa));
items.add(new Item("Restaurante Coconut", R.drawable.coco));
items.add(new Item("Rte GastroXabia", R.drawable.gastroxabia));
}
我曾计划使用此:
MisLocalesFavActivity.MyAdapter.items.add(MyAdapter.items.get(position));
所以:
public boolean onItemLongClick(AdapterView<?> parent, View v, final int position, long id) {
// TODO Auto-generated method stub
String[] opc = new String[] { "Añadir a mis locales favoritos", "Copiar", "Eliminar"};
AlertDialog opciones = new AlertDialog.Builder(
Restaurantes_Activity.this)
.setTitle("Opciones")
.setItems(opc,
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,
int selected) {
if (selected == 0) {
//acciones para editar
MisLocalesFavActivity.MyAdapter.items.add(MyAdapter.items.get(position));
Toast.makeText(getApplicationContext(),
"Añadido a mis locales favoritos! " , Toast.LENGTH_SHORT).show();
} else if (selected == 1) {
//acciones para copiar
}else if (selected == 2) {
//acciones para eliminar
}
}
}).create();
opciones.show();
return true;
}
});
但我有。新增
具体如下错误: Add方法(类型列表中的MisLocalesFavActivity.MyAdapter.Item)不适用于参数
(Restaurantes_Activity.MyAdapter.Item)
谢谢!!!
谢谢,但这不起作用,请按照错误。添加 –