列表视图按edittext搜索

时间:2016-06-11 15:21:01

标签: android listview search android-edittext

我的ListView有问题。当你点击任何一行时,它可以正常工作,但当我在EditText中写入搜索和&我点击找到的文字,它打开了另一行。

感谢您的帮助。

public class Garrote extends AppCompatActivity {
//This is app for D&D 3.5 
//lista delle garotte 

String[] listaarmigarrote = new String[]{"Bolas", "Chain", "Chain, Spiked", "Cord", "Flail, Dire", "Garrote Ring", "Locking Mechanism", "Rope", "Sling", "Steel Cable", "Whip", "Wire"};


@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_garrote);
    final ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, listaarmigarrote);
    final ListView listaarmigarrote = (ListView) findViewById(R.id.listViewgarroteweapong);

    listaarmigarrote.setAdapter(adapter);

    EditText editTextgarrote = (EditText) findViewById(R.id.editTextgarrote);
    editTextgarrote.addTextChangedListener(new TextWatcher() {
        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {

        }

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
            adapter.getFilter().filter(s);
        }

        @Override
        public void afterTextChanged(Editable s) {

        }
    });

    listaarmigarrote.getTextFilter();
    listaarmigarrote.isTextFilterEnabled();
    listaarmigarrote.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            if (position == 0) {
                Intent Bolas = new Intent(getApplicationContext(), dettagli_armi.class);
                Bolas.putExtra("costo", "5 gp");
                Bolas.putExtra("dannis", "1D3");
                Bolas.putExtra("dannim", "1D4");
                Bolas.putExtra("crit", "-");
                Bolas.putExtra("rangeinc", "-");
                Bolas.putExtra("weight", "2 lb.");
                Bolas.putExtra("type", "Exotic");
                Bolas.putExtra("dettagli", "Strangle Bonus=1.\n" +
                        " Two-handed.\n" +
                        "\n" +
                        " A bolas is a set of three weighted balls connected by leather cords.\n" +
                        " To attack, you whirl the bolas in a circle over your head and then fling it at a target.\n" +
                        " The bolas connect with your opponent with a successful ranged touch attack.\n" +
                        " Disregard any armor, shield, or natural armor bonus of the target.\n" +
                        "\n" +
                        " A character struck by bolas must make a Reflex save (with a DC equal to the attack roll of the bolas's wielder).\n" +
                        " If the saving throw fails, the target takes subdual damage and is considered pinned.\n" +
                        " (See \"Grapple\" in Chapter 8: Combat of the Player's Handbook for more information).\n" +
                        " The bolas can pin only a Tiny, Small, or Medium-size target.\n" +
                        " To escape the bolas, the pinned character must either break out (Strength check, DC 20), wriggle free (Escape Artist check, DC 20), or cut (or be cut) loose (5 hp and only slashing weapons do damage).\n" +
                        "\n" +
                        " Regardless of the method, escaping is a full-round action.\n" +
                        " (Remember that a target can use the take 10 or take 20 action to escape if the situation allows).\n" +
                        " If the saving throw succeeds, the target suffers normal damage but is not pinned.\n" +
                        " Bolas can also be used as a garrote.\n");
                Bolas.putExtra("Source", "Dragon #355");
                startActivity(Bolas);
            }
            if (position == 1) {
                Intent Chain = new Intent(getApplicationContext(), dettagli_armi.class);
                Chain.putExtra("costo", "15 gp");
                Chain.putExtra("dannis", "1D4");
                Chain.putExtra("dannim", "1D6");
                Chain.putExtra("crit", "-");
                Chain.putExtra("rangeinc", "-");
                Chain.putExtra("weight", "2 lb.");
                Chain.putExtra("type", "-");
                Chain.putExtra("dettagli", "Strangle Bonus=2.\n" +
                        " Two-handed.\n" +
                        "\n" +
                        " A chain has reach.\n" +
                        "\n" +
                        " You can strike opponents 10 feet away with it.\n" +
                        " In addition, unlike other weapons with reach, you can use it against an adjacent foe.\n" +
                        "\n" +
                        " Because the chain can wrap around an enemy's leg or other limb, you can make trip attacks with it.\n" +
                        " If you are tripped during your own trip attempt, you can drop the chain to avoid being tripped.\n");
                Chain.putExtra("Source", "Dragon #355");
                startActivity(Chain);
            }
            if (position == 2) {
                Intent ChainSpiked = new Intent(getApplicationContext(), dettagli_armi.class);
                ChainSpiked.putExtra("costo", "25 gp");
                ChainSpiked.putExtra("dannis", "1D6");
                ChainSpiked.putExtra("dannim", "1D8");
                ChainSpiked.putExtra("crit", "19-20/x2");
                ChainSpiked.putExtra("rangeinc", "-");
                ChainSpiked.putExtra("weight", "10 lb.");
                ChainSpiked.putExtra("type", "Exotic");
                ChainSpiked.putExtra("dettagli", "Strangle Bonus=2.\n" +
                        " Two-handed.\n" +
                        "\n" +
                        " A spiked chain has reach.\n" +
                        " You can strike opponents 10 feet away with it.\n" +
                        " In addition, unlike other weapons with reach, you can use it against an adjacent foe.\n" +
                        "\n" +
                        " Because the chain can wrap around an enemy's leg or other limb, you can make trip attacks with it.\n" +
                        " If you are tripped during your own trip attempt, you can drop the chain to avoid being tripped.\n" +
                        "\n" +
                        " When using a spiked chain, you get a +2 bonus on your opposed attack roll when attempting to disarm an opponent (including the roll to avoid being disarmed if you fail to disarm your opponent).\n" +
                        " You can use the Weapon Finesse feat to apply your Dexterity modifier instead of your Strength modifier to attack rolls with a spiked chain.\n");
                ChainSpiked.putExtra("Source", "Dragon #355");
                startActivity(ChainSpiked);
            }
            if (position == 3) {
                Intent Cord = new Intent(getApplicationContext(), dettagli_armi.class);
                Cord.putExtra("costo", "1 sp");
                Cord.putExtra("dannis", "1D4");
                Cord.putExtra("dannim", "1D6");
                Cord.putExtra("crit", "-");
                Cord.putExtra("rangeinc", "-");
                Cord.putExtra("weight", "1/10 lb.");
                Cord.putExtra("type", "-");
                Cord.putExtra("dettagli", "Strangle Bonus=1.\n" +
                        " Two-handed.\n" +
                        "\n" +
                        " Cord has hardness 0, 2 hit points, and a break DC of 20.\n" +
                        " Price is for 5 ft.");
                Cord.putExtra("Source", "Dragon #355");
                startActivity(Cord);
            }
            if (position == 4) {
                Intent Flaildire = new Intent(getApplicationContext(), dettagli_armi.class);
                Flaildire.putExtra("costo", "90 gp");
                Flaildire.putExtra("dannis", "1D4");
                Flaildire.putExtra("dannim", "1D6");
                Flaildire.putExtra("crit", "19-20/x2");
                Flaildire.putExtra("rangeinc", "-");
                Flaildire.putExtra("weight", "10 lb.");
                Flaildire.putExtra("type", "Exotic");
                Flaildire.putExtra("dettagli", "Strangle Bonus=2.\n" +
                        " Two-handed.\n" +
                        "\n" +
                        " A dire flail is a double weapon.\n" +
                        " You can fight with it as if fighting with two weapons, but if you do, you incur all the normal attack penalties associated with fighting with two weapons, as if you were using a one-handed weapon and a light weapon.\n" +
                        " A creature using a double weapon in one hand, such as an ogre using a dire flail, can't use it as a double weapon.\n" +
                        "\n" +
                        " With a dire flail, you get a +2 bonus on your opposed attack roll when attempting to disarm an enemy (including the opposed attack roll to avoid being disarmed if you fail to disarm your enemy).\n" +
                        " You can also use this weapon to make trip attacks.\n" +
                        " If you are tripped during your own trip attempt, you can drop the dire flail to avoid being tripped.\n");
                Flaildire.putExtra("Source", "Dragon #355");
                startActivity(Flaildire);
            }
            if (position == 5) {
                Intent GarroteRing = new Intent(getApplicationContext(), dettagli_armi.class);
                GarroteRing.putExtra("costo", "50 gp");
                GarroteRing.putExtra("dannis", "1D6");
                GarroteRing.putExtra("dannim", "1D8");
                GarroteRing.putExtra("crit", "18-20");
                GarroteRing.putExtra("rangeinc", "-");
                GarroteRing.putExtra("weight", "- lb.");
                GarroteRing.putExtra("type", "Slashing.\n");
                GarroteRing.putExtra("dettagli", "The wearer of this large, ostentatious ring can detach the gem atop it and pull forth a length of extremely fine, tough wire that can be used to strangle an opponent.\n" +
                        " Pulling out the wire is a free action, but rewinding it requires a full-round action.\n" +
                        " A garrotte attack uses the grappling rules from the Player's Handbook, with a few additions.\n");
                GarroteRing.putExtra("Source", "Dragon #316");
                startActivity(GarroteRing);
            }
            if (position == 6) {
                Intent Cord = new Intent(getApplicationContext(), dettagli_armi.class);
                Cord.putExtra("costo", "1 sp");
                Cord.putExtra("dannis", "1D4");
                Cord.putExtra("dannim", "1D6");
                Cord.putExtra("crit", "-");
                Cord.putExtra("rangeinc", "-");
                Cord.putExtra("weight", "1/10 lb.");
                Cord.putExtra("type", "-");
                Cord.putExtra("dettagli", "Strangle Bonus=1" +
                        " Two-handed.\n" +
                        "\n" +
                        " Cord has hardness 0, 2 hit points, and a break DC of 20.\n" +
                        " Price is for 5 ft.\n");
                Cord.putExtra("Source", "Dragon #355");
                startActivity(Cord);
            }
            if (position == 7) {
                Intent LockingMechanism = new Intent(getApplicationContext(), dettagli_armi.class);
                LockingMechanism.putExtra("costo", "-");
                LockingMechanism.putExtra("dannis", "-");
                LockingMechanism.putExtra("dannim", "-");
                LockingMechanism.putExtra("crit", "-");
                LockingMechanism.putExtra("rangeinc", "-");
                LockingMechanism.putExtra("weight", "-");
                LockingMechanism.putExtra("type", "Exotic");
                LockingMechanism.putExtra("dettagli", "Strangle Bonus=-.\n" +
                        " Two-handed.\n" +
                        "\n" +
                        " A locking mechanism consists of a pair of handles that attach to any thin, supple item (such as a rope, steel cable, wire, and so on).\n" +
                        " The handles slide along the garroting material freely, but when brought together they can lock in place together.\n" +
                        " Once you secure the garrote you can lock the garrote in place with a move action.\n" +
                        "\n" +
                        " This maintains strangling pressure on your opponent even after you let go.\n" +
                        " The garroted creature continues to make grapple checks (each one opposed by the last grapple check you made) until freed or unconscious.\n" +
                        " Unlocking the handles from each other is a free action.\n" +
                        " Adding a locking mechanism to a garrote makes the garrote an exotic weapon.\n" +
                        "\n" +
                        " The DC for a Disable Device check made to remove a locked garrote is 10 if the character has Exotic Weapon Proficiency (locking garrote) or 25 if she does not.\n" +
                        " If someone other than the victim makes the attempt, a -5 penalty applies unless the garroted character is held, unconscious, or otherwise kept from moving.\n" +
                        "\n" +
                        " A character attempting to remove a locked garrote from around his own neck takes a -5 penalty for working blindly.\n" +
                        " A character cannot take 10 or take 20 on this check unless the creature garroted is already dead.\n" +
                        " Failing a Disable Device check by 5 or more causes the victim to lose an additional round's worth of air (or deals a round's worth of damage, if using those rules).\n");
                LockingMechanism.putExtra("Source", "Dragon #355");
                startActivity(LockingMechanism);
            }
            if (position == 8) {
                Intent Rope = new Intent(getApplicationContext(), dettagli_armi.class);
                Rope.putExtra("costo", "varies");
                Rope.putExtra("dannis", "1D3");
                Rope.putExtra("dannim", "1D4");
                Rope.putExtra("crit", "-");
                Rope.putExtra("rangeinc", "-");
                Rope.putExtra("weight", "-");
                Rope.putExtra("type", "varies");
                Rope.putExtra("dettagli", "Strangle Bonus=1.\n" +
                        " Two-handed.\n" +
                        "\n" +
                        " A standard piece of adventuring equipment, a rope can be used as a garrote.\n");
                Rope.putExtra("Source", "Dragon #355");
                startActivity(Rope);
            }
            if (position == 9) {
                Intent Sling = new Intent(getApplicationContext(), dettagli_armi.class);
                Sling.putExtra("costo", "1 gp");
                Sling.putExtra("dannis", "1D2");
                Sling.putExtra("dannim", "1D3");
                Sling.putExtra("crit", "-");
                Sling.putExtra("rangeinc", "-");
                Sling.putExtra("weight", "0 lb.");
                Sling.putExtra("type", "-");
                Sling.putExtra("dettagli", "Strangle Bonus=1.\n" +
                        " Two-handed.\n" +
                        "\n" +
                        " The sling hurls lead bullets.\n" +
                        " It's nor as easy to use as the crossbow nor as powerful as a bow, but it's cheap, and easy to improvise from common materials.\n" +
                        " Druids and halflings favor slings.\n" +
                        "\n" +
                        " You can hurl ordinary stones with a sling, but stones are not as dense or as round as bullets, so you deal only 1d3 points of damage and suffer a -1 penalty on attack rolls.\n");
                Sling.putExtra("Source", "Dragon #355");
                startActivity(Sling);
            }
            if (position == 10) {
                Intent SteelCable = new Intent(getApplicationContext(), dettagli_armi.class);
                SteelCable.putExtra("costo", "60 gp");
                SteelCable.putExtra("dannis", "1D6");
                SteelCable.putExtra("dannim", "1D8");
                SteelCable.putExtra("crit", "-");
                SteelCable.putExtra("rangeinc", "-");
                SteelCable.putExtra("weight", "1 lb.");
                SteelCable.putExtra("type", "-");
                SteelCable.putExtra("dettagli", "Strangle Bonus=3.\n" +
                        " Two-handed.\n" +
                        "\n" +
                        " Steel cable has hardness 8, 8 hit points, and a break DC of 26.\n" +
                        " Price is for 5 ft.");
                SteelCable.putExtra("Source", "Dragon #355");
                startActivity(SteelCable);
            }
            if (position == 11) {
                Intent Whip = new Intent(getApplicationContext(), dettagli_armi.class);
                Whip.putExtra("costo", "1 gp");
                Whip.putExtra("dannis", "1D6");
                Whip.putExtra("dannim", "1D8");
                Whip.putExtra("crit", "-");
                Whip.putExtra("rangeinc", "-");
                Whip.putExtra("weight", "2 lb.");
                Whip.putExtra("type", "Exotic");
                Whip.putExtra("dettagli", "Strangle Bonus=3.\n" +
                        " Two-handed.\n" +
                        "\n" +
                        " The whip deals subdual damage.\n" +
                        " It deals no damage to any creature with even a +1 armor bonus or at least a +3 natural armor bonus.\n" +
                        " Although you keep it in hand, treat it as a projectile weapon with a maximum range of 15 feet and no range penalties.\n" +
                        "\n" +
                        " Because the whip can wrap around an enemy's leg or other limb, you can make trip attacks with it.\n" +
                        " If you are tripped during your own trip attempt, you can drop the whip to avoid being tripped.\n" +
                        "\n" +
                        " When using a whip, you get a +2 bonus on your opposed attack roll when attempting to disarm an opponent (including the roll to keep from being disarmed if you fail to disarm your opponent).\n");
                Whip.putExtra("Source", "Dragon #355");
                startActivity(Whip);
            }
            if (position == 12) {
                Intent Wire = new Intent(getApplicationContext(), dettagli_armi.class);
                Wire.putExtra("costo", "25 gp");
                Wire.putExtra("dannis", "1D4");
                Wire.putExtra("dannim", "1D6");
                Wire.putExtra("crit", "-");
                Wire.putExtra("rangeinc", "-");
                Wire.putExtra("weight", "0 lb.");
                Wire.putExtra("type", "-");
                Wire.putExtra("dettagli", "Strangle Bonus=3.\n" +
                        " Two-handed.\n" +
                        "\n" +
                        " Most wire garrotes come with grips at the ends.\n" +
                        " Using a wire garrote without grips or some kind of hand protection deals 1d3 points of damage per round to you.\n" +
                        " Wire has hardness 4, 5 hit points, and a break DC of 24.\n" +
                        " Assumes 5 ft. length.\n");
                Wire.putExtra("Source", "Dragon #355");
                startActivity(Wire);
            }

        }
    });


}

1 个答案:

答案 0 :(得分:0)

首先,像你这样写OnItemClickListener并不好(如果用开关盒替换它们太多了)。您可以粘贴一些标签来查看对应位置,这可能有所帮助。

或尝试根据视图中的某些文字进行搜索。