繁体   English   中英

要将自定义对象数据传输到另一个活动?

[英]Transferring custom object data to another activity?

根据我之前的一篇文章的建议,我通过将String ArrayList更改为包含Spelltable类型的Arraylist的Arraylist对项目进行了一些编辑,其中Spelltable包含字符串名称和字符串描述。 我正在尝试将此信息从主要活动转移到我的其他活动。 任何帮助,将不胜感激?。 这是我的代码:

打包com.example.admin.spelltable;

import android.app.Activity;
import android.app.Application;
import android.content.ClipData;
import android.content.Intent;
import android.content.pm.ApplicationInfo;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.Toolbar;
import android.text.Layout;
import android.view.View;
import android.webkit.WebView;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ListView;
import android.widget.TextView;
import org.w3c.dom.Text;
import java.util.ArrayList;
import java.util.List;

public class Spelltable extends AppCompatActivity {
ListView mySpellbook;
ArrayList<SelectedSpell> spells = new ArrayList<SelectedSpell>();
ArrayAdapter adapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_spelltable);
    mySpellbook = findViewById(R.id.mySpellbook);

    //Spell Names
    spells.add(new SelectedSpell("Abi-Dalzim's Horrid Wiliting", "You draw the moisture from every creature in a 30-foot cube centered on a point you choose within range. Each creature in that area must make a Constitution saving throw. Constructs and undead aren’t affected, and plants and water elementals make this saving throw with disadvantage. A creature takes 12d8 necrotic damage on a failed save, or half as much damage on a successful one.\n" +
            "Nonmagical plants in the area that aren’t creatures, such as trees and shrubs, wither and die instantly."));
    /*spells.add("Absorb Elements");
    spells.add("Acid Splash");
    spells.add("Aganazzar's Scorcher");
    spells.add("Aid");
    spells.add("Alarm");
    spells.add("Alter Self");
    spells.add("Animal Friendship");
    spells.add("Animal Messenger");
    spells.add("Animal Shapes");
    spells.add("Animate Dead");
    spells.add("Animate Objects");
    spells.add("Antilife Shell");
    spells.add("Antimagic Field");
    spells.add("Antipathy/Sympathy");
    spells.add("Arcane Eye");
    spells.add("Arcane Gate");
    spells.add("Arcane Lock");
    spells.add("Armor of Agathys");
    spells.add("Arms of Hadar");
    spells.add("Astral Projection");
    spells.add("Augury");
    spells.add("Aura of Life");
    spells.add("Aura of Purity");
    spells.add("Aura of Vitality");
    spells.add("Awaken");
    spells.add("Bane");
    spells.add("Banishing Smite");
    spells.add("Banishment");
    spells.add("Barkskin");
    spells.add("Beacon of Hope");
    spells.add("Barkskin");
    spells.add("Beast Bond");
    spells.add("Beast Sense");
    spells.add("Bestow Curse");
    spells.add("Bidby's Hand");
    spells.add("Blade Barrier");
    spells.add("Blade Ward");
    spells.add("Bless");
    spells.add("Blight");
    spells.add("Blinding Smite");
    spells.add("Blindness/Deafness");
    spells.add("Blink");
    spells.add("Blur");
    spells.add("Bones of the Earth");
    spells.add("Booming Blade");
    spells.add("Branding Smite");
    spells.add("Burning Hands");
    spells.add("Call Lightning");
    spells.add("Calm Emotions");
    spells.add("Catapult");
    spells.add("Catnap");
    spells.add("Cause Fear");
    spells.add("Ceremony");
    spells.add("Chain Lightning");
    spells.add("Chaos Bolt");
    spells.add("Charm Monster");
    spells.add("Charm Person");
    spells.add("Chill Touch");
    spells.add("Chromatic Orb");
    spells.add("Circle of Death");
    spells.add("Circle of Power");
    spells.add("Clairvoyance");
    spells.add("Clone");
    spells.add("Cloud of Daggers");
    spells.add("Cloudkill");
    spells.add("Color Spray");
    spells.add("Command");
    spells.add("Commune");
    spells.add("Commune with Nature");
    spells.add("Compelled Duel");
    spells.add("Comprehend Languages");
    spells.add("Compulsion");
    spells.add("Cone of Cold");
    spells.add("Confusion");
    spells.add("Conjure Animals");
    spells.add("Conjure Barrage");
    spells.add("Conjure Celestial");
    spells.add("Conjure Elemental");
    spells.add("Conjure Fey");
    spells.add("Conjure Minor Elementals");
    spells.add("Conjure Volley");
    spells.add("Conjure Woodland Beings");
    spells.add("Contact Other Plane");
    spells.add("Contagion");
    spells.add("Contingency");
    spells.add("Continual Flame");
    spells.add("Control Flames");
    spells.add("Control Water");
    spells.add("Control Weather");
    spells.add("Control Winds");
    spells.add("Cordon of Arrows");
    spells.add("Counterspell");
    spells.add("Create Bonefire");
    spells.add("Create Food and Water");
    spells.add("Create Homunculus");
    spells.add("Create or Destroy Water");
    spells.add("Create Undead");
    spells.add("Creation");
    spells.add("Crown of Madness");
    spells.add("Crown of Stars");
    spells.add("Crusader's Mantle");
    spells.add("Cure Wounds");
    spells.add("Dancing Lights");
    spells.add("Danse Macabre");
    spells.add("Darkness");
    spells.add("Darkvision");
    spells.add("Dawn");
    spells.add("Daylight");
    spells.add("Death Ward");
    spells.add("Delayed Blast Fireball");
    spells.add("Demiplane");
    spells.add("Destructive Wave");
    spells.add("Detect Evil and Good");
    spells.add("Detect Magic");
    spells.add("Detect Poison and Disease");
    spells.add("Detect Thoughts");
    spells.add("Dimension Door");
    spells.add("Disguise Self");
    spells.add("Disintegrate");
    spells.add("Dispel Evil and Good");
    spells.add("Dispel Magic");
    spells.add("Dissonant Whispers");
    spells.add("Divination");
    spells.add("Divine Favor");
    spells.add("Divine Word");
    spells.add("Dominate Beast");
    spells.add("Dominate Monster");
    spells.add("Dominate Person");
    spells.add("Dragon's Breath");
    spells.add("Drawmij's Instant Summons");
    spells.add("Dream");
    spells.add("Druid Grove");
    spells.add("Druidcraft");
    spells.add("Dust Devil");
    spells.add("Earth Tremor");
    spells.add("Earthbind");
    spells.add("Earthquake");
    spells.add("Eldritch Blast");
    spells.add("Elemental Bane");
    spells.add("Elemental Weapon");
    spells.add("Enemies Abound");
    spells.add("Enervation");
    spells.add("Enhance Ability");
    spells.add("Enlarge/Reduce");
    spells.add("Ensnaring Strike");
    spells.add("Entangle");
    spells.add("Enthrall");
    spells.add("Erupting Earth");
    spells.add("Etherealness");
    spells.add("Evard's Black Tentacles");
    spells.add("Expeditious Retreat");
    spells.add("Eyebite");
    spells.add("Fabricate");
    spells.add("Faerie Fire");
    spells.add("False Life");
    spells.add("Far Step");
    spells.add("Fear");
    spells.add("Feather Fall");
    spells.add("Feeblemind");
    spells.add("Feign Death");
    spells.add("Find Familiar");
    spells.add("Find Greater Steed");
    spells.add("Find Steed");
    spells.add("Find the Path");
    spells.add("Find Traps");
    spells.add("Finger of Death");
    spells.add("Fire Bolt");
    spells.add("Fire Shield");
    spells.add("Fire Storm");
    spells.add("Fireball");
    spells.add("Flame Arrows");
    spells.add("Flame Blade");
    spells.add("Flame Strike");
    spells.add("Flaming Sphere");
    spells.add("Flesh to Stone");
    spells.add("Fly");
    spells.add("Fog Cloud");
    spells.add("Forbiddance");
    spells.add("Forcecage");
    spells.add("Foresight");
    spells.add("Freedom of Movement");
    spells.add("Friends");
    spells.add("Frostbite");
    spells.add("Gaseous Form");
    spells.add("Geas");
    spells.add("Gentle Repose");
    spells.add("Giant Insect");
    spells.add("Glibness");
    spells.add("Globe of Invulnerability");
    spells.add("Glyph of Wards");
    spells.add("Goodberry");
    spells.add("Grasping Vine");
    spells.add("Grease");
    spells.add("Greater Invisibility");
    spells.add("Greater Restoration");
    spells.add("Green-Flame Blade");
    spells.add("Guardian of Faith");
    spells.add("Guardian of Nature");
    spells.add("Guards and Wards");
    spells.add("Guidance");
    spells.add("Guiding Bolt");
    spells.add("Gust");
    spells.add("Gust of Wind");
    spells.add("Hail of Thorns");
    spells.add("Hallow");
    spells.add("Hallucinatory Terrain");
    spells.add("Harm");
    spells.add("Haste");
    spells.add("Heal");
    spells.add("Healing Spirit");
    spells.add("Healing Word");
    spells.add("Heat Metal");
    spells.add("Hellish Rebuke");
    spells.add("Heroes' Feast");
    spells.add("Heroism");
    spells.add("Hex");
    spells.add("Hold Monster");
    spells.add("Hold Person");
    spells.add("Holy Aura");
    spells.add("Holy Weapon");
    spells.add("Hunger of Hadar");
    spells.add("Hunter's Mark");
    spells.add("Hypnotic Pattern");
    spells.add("Ice Knife");
    spells.add("Ice Storm");
    spells.add("Identify");
    spells.add("Illusory Dragon");
    spells.add("Illusory Script");
    spells.add("Immolation");
    spells.add("Imprisonment");
    spells.add("Incendiary Cloud");
    spells.add("Infernal Calling");
    spells.add("Infestation");
    spells.add("Inflict Wounds");
    spells.add("Insect Plague");
    spells.add("Investiture of Flame");
    spells.add("Investiture of Ice");
    spells.add("Investiture of Stone");
    spells.add("Investiture of Wind");
    spells.add("Invisibility");
    spells.add("Invulnerability");
    spells.add("Jump");
    spells.add("Knock");
    spells.add("Legend Lore");
    spells.add("Leomund's Secret Chest");
    spells.add("Leomund's Tiny Hut");
    spells.add("Lesser Restoration");
    spells.add("Levitate");
    spells.add("Life Transference");
    spells.add("Light");
    spells.add("Lightning Arrow");
    spells.add("Lightning Bolt");
    spells.add("Lightning Lure");
    spells.add("Locate Animals or Plants");
    spells.add("Locate Creature");
    spells.add("Locate Object");
    spells.add("Longstrider");
    spells.add("Maddening Darkness");
    spells.add("Maelstrom");
    spells.add("Mage Armor");
    spells.add("Mage Hand");
    spells.add("Mage Circle");
    spells.add("Magic Jar");
    spells.add("Magic Missile");
    spells.add("Magic Mouth");
    spells.add("Magic Stone");
    spells.add("Magic Weapon");
    spells.add("Major Image");
    spells.add("Mass Cure Wounds");
    spells.add("Mass Heal");
    spells.add("Mass Healing Word");
    spells.add("Mass Polymorph");
    spells.add("Mass Suggestion");
    spells.add("Maximilian's Earthen Grasp");
    spells.add("Maze");
    spells.add("Meld into Stone");
    spells.add("Melf's Acid Arrow");
    spells.add("Melf's Minute Meteors");
    spells.add("Mending");
    spells.add("Mental Prison");
    spells.add("Message");
    spells.add("Meteor Swarm");
    spells.add("Mighty Fortress");
    spells.add("Mind Blank");
    spells.add("Mind Spike");
    spells.add("Minor Illusion");
    spells.add("Mirage Arcane");
    spells.add("Mirror Image");
    spells.add("Mislead");
    spells.add("Misty Step");
    spells.add("Modify Memory");
    spells.add("Mold Earth");
    spells.add("Moonbeam");
    spells.add("Mordenkainen's Faithful Hound");
    spells.add("Mordenkainen's Magnificent Mansion");
    spells.add("Mordenkainen's Private Sanctum");
    spells.add("Mordenkainen's Sword");
    spells.add("Move Earth");
    spells.add("Negative Energy Flood");
    spells.add("Nondetection");
    spells.add("Nystul's Magic Aura");
    spells.add("Otiluke's Freezing Sphere");
    spells.add("Otiluke's Resilient Sphere");
    spells.add("Otto's Irresistible Dance");
    spells.add("Pass Without Trace");
    spells.add("Passwall");
    spells.add("Phantasmal Force");
    spells.add("Phantasmal Killer");
    spells.add("Phantom Steed");
    spells.add("Planar Ally");
    spells.add("Planar Binding");
    spells.add("Plane Shift");
    spells.add("Plant Growth");
    spells.add("Poison Spray");
    spells.add("Polymorph");
    spells.add("Power Word Heal");
    spells.add("Power Word Kill");
    spells.add("Power Word Pain");
    spells.add("Power Word Stun");
    spells.add("Prayer of Healing");
    spells.add("Prestidigitation");
    spells.add("Primal Savagery");
    spells.add("Primordial Ward");
    spells.add("Prismatic Spray");
    spells.add("Prismatic Wall");
    spells.add("Produce Flame");
    spells.add("Programmed Illusion");
    spells.add("Project Image");
    spells.add("Protection from Energy");
    spells.add("Protection from Evil and Good");
    spells.add("Protection from Poison");
    spells.add("Psychic Scream");
    spells.add("Purify Food and Drink");
    spells.add("Pyrotechnics");
    spells.add("Raise Dead");
    spells.add("Rary's Telepathic Bond");
    spells.add("Ray of Enfeeblement");
    spells.add("Rat of Frost");
    spells.add("Ray of Sickness");
    spells.add("Regenerate");
    spells.add("Reincarnate");
    spells.add("Remove Curse");
    spells.add("Resistance");
    spells.add("Resurrection");
    spells.add("Reverse Gravity");
    spells.add("Revivify");
    spells.add("Rope Trick");
    spells.add("Sacred Flame");
    spells.add("Sanctuary");
    spells.add("Scatter");
    spells.add("Scorching Ray");
    spells.add("Scrying");
    spells.add("Searing Smite");
    spells.add("See Invisibility");
    spells.add("Seeming");
    spells.add("Sending");
    spells.add("Sequester");
    spells.add("Shadow Blade");
    spells.add("Shadow of Moil");
    spells.add("Shape Water");
    spells.add("Shapechange");
    spells.add("Shatter");
    spells.add("Shield");
    spells.add("Shield of Faith");
    spells.add("Shillelagh");
    spells.add("Shocking Grasp");
    spells.add("Sickening Radiance");
    spells.add("Silence");
    spells.add("Silent Image");
    spells.add("Simulacrum");
    spells.add("Skill Empowerment");
    spells.add("Skywrite");
    spells.add("Sleep");
    spells.add("Sleet Storm");
    spells.add("Slow");
    spells.add("Snare");
    spells.add("Snilloc's Snowball Swarm");
    spells.add("Soul Cage");
    spells.add("Spare the Dying");
    spells.add("Speak with Animals");
    spells.add("Speak with Dead");
    spells.add("Speak with Plants");
    spells.add("Spider Climb");
    spells.add("Spike Growth");
    spells.add("Spirit Guardians");
    spells.add("Spiritual Weapon");
    spells.add("Staggering Smite");
    spells.add("Steel Wind Strike");
    spells.add("Stinking Cloud");
    spells.add("Stone Shape");
    spells.add("Stoneskin");
    spells.add("Storm of Vengeance");
    spells.add("Storm Sphere");
    spells.add("Suggestion");
    spells.add("Summon Greater Demon");
    spells.add("Summon Lesser Demons");
    spells.add("Sunbeam");
    spells.add("Sunburst");
    spells.add("Swift Quiver");
    spells.add("Sword Burst");
    spells.add("Symbol");
    spells.add("Synaptic Static");
    spells.add("Tasha's Hideous Laughter");
    spells.add("Telekinesis");
    spells.add("Telepathy");
    spells.add("Teleport");
    spells.add("Teleportation Circle");
    spells.add("Temple of the Gods");
    spells.add("Tenser's Floating Disk");
    spells.add("Tenser's Transformation");
    spells.add("Thaumaturgy");
    spells.add("Thorn Whip");
    spells.add("Thunder Step");
    spells.add("Thunderclap");
    spells.add("Thunderous Smite");
    spells.add("Thunderwave");
    spells.add("Tidal Wave");
    spells.add("Time Stop");
    spells.add("Tiny Servant");
    spells.add("Toll the Dead");
    spells.add("Tongues");
    spells.add("Transmute Rock");
    spells.add("Transport via Plants");
    spells.add("Tree Stride");
    spells.add("True Polymorph");
    spells.add("True Resurrection");
    spells.add("True Seeing");
    spells.add("True Strike");
    spells.add("Tsunami");
    spells.add("Unseen Servant");
    spells.add("Vampiric Touch");
    spells.add("Vicious Mockery");
    spells.add("Vitriolic Sphere");
    spells.add("Wall of Fire");
    spells.add("Wall of Force");
    spells.add("Wall of Ice");
    spells.add("Wall of Light");
    spells.add("Wall of Sand");
    spells.add("Wall of Stone");
    spells.add("Wall of Thorns");
    spells.add("Wall of Water");
    spells.add("Warding Bond");
    spells.add("Water Breathing");
    spells.add("Water Walk");
    spells.add("Watery Sphere");
    spells.add("Web");
    spells.add("Weird");
    spells.add("Whirlwind");
    spells.add("Wind Walk");
    spells.add("Wind Wall");
    spells.add("Wish");
    spells.add("Witch Bolt");
    spells.add("Word of Radiance");
    spells.add(new SelectedSpell("Word of Recall","you"));
    spells.add("Wrath of Nature");
    spells.add("Wrathful Smite");
    spells.add("Zephyr Strike");
    spells.add("Zone of Truth");*/

    final Intent intent = new Intent(this, SelectedSpell.class);
    intent.putExtra("spells", spells);

    //final Intent selectedspell = new Intent(this, SelectedSpell.class);
    //Link to spelltable
    adapter = new ArrayAdapter(Spelltable.this, android.R.layout.simple_list_item_1,spells);
    mySpellbook.setAdapter(adapter);

    mySpellbook.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            startActivity(intent);
        }

    });

}

}

为了将您的咒语列表从一个活动传递到另一个活动, SelectedSpell对象需要实现Parcelable

检查文档示例

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM