Autore Topic: Listview simple_item_2  (Letto 139 volte)

Offline Jekan

  • Nuovo arrivato
  • *
  • Post: 21
  • Respect: 0
    • Mostra profilo
  • Dispositivo Android:
    Sony Experia M
  • Sistema operativo:
    Windows 7
Listview simple_item_2
« il: 29 Settembre 2016, 17:54:02 CEST »
0
 :-) :-)Salve ragazzi, spero qualcuno mi sappia aiutare vorrei usare simple_list_item_2 usando pero due stringe fino adesso ho usato l'arrayadapter di android studio con simple_list_item_1.
Adesso vorrei usare simple_list_item_2 ma senza creare un adapter ma usando sempre uno di android studio se è possibile,
Codice (Java): [Seleziona]
package jekan.myapplication;

import android.content.Intent;
import android.graphics.Color;
import android.renderscript.Sampler;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.Spinner;
import android.widget.TextView;

import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.AdView;
import com.google.android.gms.ads.MobileAds;

import java.io.BufferedReader;
import java.io.File;
import java.io.InputStream;
import java.io.InputStreamReader;

public class ammunition extends AppCompatActivity {

   String[] listaammunition = new String[]{"Arrow Zigzag","Arrow, Alchemist’s Fire(1)"};

    EditText inputSearch;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_ammunition);

        final ArrayAdapter<String> adapter = new ArrayAdapter<String>(getApplicationContext(),
                android.R.layout.simple_list_item_1, listaammunition) {
            @Override
            public View getView(int position, View convertView, ViewGroup parent) {
                View view = super.getView(position, convertView, parent);
                TextView text = (TextView) view.findViewById(android.R.id.text1);
                text.setTextColor(Color.BLACK);
                return view;
            }
        };

        ListView listViewammunition = (ListView) findViewById(R.id.listViewammunition);
        listViewammunition.setAdapter(adapter);


        inputSearch = (EditText) findViewById(R.id.inputSearchmunizioni);

        inputSearch.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) {

            }
        });


        listViewammunition.setOnItemClickListener(new AdapterView.OnItemClickListener() {

            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {

                String Arrowalchemistsfire = adapter.getItem(position);
                if (Arrowalchemistsfire.equals("Arrow, Alchemist’s Fire(1)")) {
                    Intent Arrowalchemistsfire1 = new Intent(getApplicationContext(), dettagli_armi.class);
                    Arrowalchemistsfire1.putExtra("costo", "75 gp");
                    Arrowalchemistsfire1.putExtra("dannis", "1D4");
                    Arrowalchemistsfire1.putExtra("dannim", "1D4");
                    Arrowalchemistsfire1.putExtra("crit", "x2");
                    Arrowalchemistsfire1.putExtra("rangeinc", "30 ft.");
                    Arrowalchemistsfire1.putExtra("weight", "1/5 lb.");
                    Arrowalchemistsfire1.putExtra("type", "fire");
                    Arrowalchemistsfire1.putExtra("dettagli", "Each of these projectiles carries a deadly load of alchemist's fire in its hollow shaft.\n" +
                            " When it strikes a target, the arrow's shaft shatters, releasing the alchemist's fire directly onto the target. One round after impact, the alchemist's fire ignites, dealing 1d4 points of damage.\n" +
                            "\n" +
                            " The target can use a full-round action to attempt to extinguish the flames before taking this damage. It takes a successful Reflex saving throw (DC 15) to extinguish the flames.\n" +
                            " Rolling on the ground earns the target a +2 bonus on the save. Submerging (such as by leaping into a lake) or magically extinguishing the flames automatically kills the flames.\n");
                    Arrowalchemistsfire1.putExtra("Source", "Dragon #349");
                    startActivity(Arrowalchemistsfire1);
                }
                String Arrowalchemistsfrost = adapter.getItem(position);
                if (Arrowalchemistsfrost.equals("Arrow, Alchemist’s Frost(1)")) {
                    Intent Arrowalchemistsfrost1 = new Intent(getApplicationContext(), dettagli_armi.class);
                    Arrowalchemistsfrost1.putExtra("costo", "75 gp");
                    Arrowalchemistsfrost1.putExtra("dannis", "1D4");
                    Arrowalchemistsfrost1.putExtra("dannim", "1D4");
                    Arrowalchemistsfrost1.putExtra("crit", "x2");
                    Arrowalchemistsfrost1.putExtra("rangeinc", "30 ft.");
                    Arrowalchemistsfrost1.putExtra("weight", "1/5 lb.");
                    Arrowalchemistsfrost1.putExtra("type", "cold");
                    Arrowalchemistsfrost1.putExtra("dettagli", "Similar in designed to the Arrow alchemist's fire, this arrow instead carrier an alchemical compound that creates a spray of intense cold.\n" +
                            " If the arrow strikes a target, the arrow immediately shatters and deals 1d4 points of cold damage.\n");
                    Arrowalchemistsfrost1.putExtra("Source", "Dragon #349");
                    startActivity(Arrowalchemistsfrost1);
                }              
        });
    }
}

Vorrei un sub item a queste due voci :-P :-P Grazie in anticipo O:-)

Offline joefermati

  • Nuovo arrivato
  • *
  • Post: 10
  • Respect: +1
    • Mostra profilo
  • Sistema operativo:
    win 10
Re:Listview simple_item_2
« Risposta #1 il: 05 Ottobre 2016, 13:47:44 CEST »
0
Spiega meglio il layout finale che vuoi ottenere.

Secondo me ti conviene creare un Adapter personalizzato così puoi usare un list_item personalizzato.

O meglio, usa una recycler view.

Offline Jekan

  • Nuovo arrivato
  • *
  • Post: 21
  • Respect: 0
    • Mostra profilo
  • Dispositivo Android:
    Sony Experia M
  • Sistema operativo:
    Windows 7
Re:Listview simple_item_2
« Risposta #2 il: 05 Ottobre 2016, 16:35:33 CEST »
0
Vorei creare una listview cosi ma invece di "www.ecc.." vorrei mettere altri dati