我有一個在活動中使用自定義適配器填充的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)
謝謝!!!
謝謝,但這不起作用,請按照錯誤。添加 –