Skip to main content
adicionou 306 caracteres ao conteúdo
Fonte Link
vitu
  • 11
  • 2
public class artilheiros extends AppCompatActivity {

int [] Imagens = {R.drawable.arg, R.drawable.bolivia, R.drawable.brasil, R.drawable.chile,
          R.drawable.colombia, R.drawable.chile, R.drawable.paraguai, R.drawable.uruguai,
          R.drawable.arg, R.drawable.bolivia, R.drawable.brasil, R.drawable.chile,
          R.drawable.colombia, R.drawable.chile, R.drawable.paraguai};

String [] Nomes = {"ART 1", "ART 2", "ART 3", "ART 4", "ART 5", "ART 6", "ART 7", "ART 8",
                    "ART 9", "ART 10", "ART 11", "ART 12", "ART 13", "ART 14", "ART 15"};

String [] Times = {"TIME 1", "TIME 2", "TIME 3", "TIME 4", "TIME 5", "TIME 6", "TIME 7",
        "TIME 8", "TIME 9", "TIME 10", "TIME 11", "TIME 12", "TIME 13", "TIME 14", "TIME 15"};

String [] Gols = {"999 gols", "999 gols", "999 gols", "999 gols", "999 gols", "999 gols", "999 gols", "999 gols", "999 gols", "999 gols", "999 gols", "999 gols", "999 gols", "999 gols", "999 gols"};


String [] Gols = {"999 gols", "999 gols", "999 gols", "999 gols", "999 gols", "999 gols", "999 gols",
       "999 gols", "999 gols", "999 gols", "999 gols", "999 gols", "999 gols", "999 gols", "999 gols"};



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

    ListView listview = findViewById(R.id.listviewart);

    CustomAdapter customAdapter = new CustomAdapter();

    listview.setAdapter(customAdapter);

}

class CustomAdapter extends BaseAdapter{


    @Override
    public int getCount() {
        return Imagens.length;
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        convertView = getLayoutInflater().inflate(R.layout.customlistview, null);
        ImageView imageView = (ImageView) convertView.findViewById(R.id.imageView);
        TextView textViewnome = (TextView) convertView.findViewById(R.id.textViewnome);
        TextView textViewtime = (TextView) convertView.findViewById(R.id.textViewtime);
        TextView textViewgols = (TextView) convertView.findViewById(R.id.textViewgols);

        imageView.setImageResource(Imagens[position]);
        textViewnome.setText(Nomes[position]);
        textViewtime.setText(Times[position]);
       textViewgols.setText(Gols[position]);


        return convertView;
    }
}
 

Tentei usarEu usei esse o metodo abaixo, masporém todos os itens da erro, desculpem qualquer errolista abrem a mesma activity...

  int position = getIntent().getIntExtra("a", 0);

    listview.setOnClickListenersetOnItemClickListener(new AdapterView.OnItemClickListener() { 

        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            artilheiros a1 = (artilheiros) listview.getItemAtPosition(0);
            Intent it = new Intent(artilheiros.this, campeoes.class);
            it.putExtra("a1", position);
            startActivity(it);
        }
    });
public class artilheiros extends AppCompatActivity {

int [] Imagens = {R.drawable.arg, R.drawable.bolivia, R.drawable.brasil, R.drawable.chile,
          R.drawable.colombia, R.drawable.chile, R.drawable.paraguai, R.drawable.uruguai,
          R.drawable.arg, R.drawable.bolivia, R.drawable.brasil, R.drawable.chile,
          R.drawable.colombia, R.drawable.chile, R.drawable.paraguai};

String [] Nomes = {"ART 1", "ART 2", "ART 3", "ART 4", "ART 5", "ART 6", "ART 7", "ART 8",
                    "ART 9", "ART 10", "ART 11", "ART 12", "ART 13", "ART 14", "ART 15"};

String [] Times = {"TIME 1", "TIME 2", "TIME 3", "TIME 4", "TIME 5", "TIME 6", "TIME 7",
        "TIME 8", "TIME 9", "TIME 10", "TIME 11", "TIME 12", "TIME 13", "TIME 14", "TIME 15"};

String [] Gols = {"999 gols", "999 gols", "999 gols", "999 gols", "999 gols", "999 gols", "999 gols", "999 gols", "999 gols", "999 gols", "999 gols", "999 gols", "999 gols", "999 gols", "999 gols"};

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

    ListView listview = findViewById(R.id.listviewart);

    CustomAdapter customAdapter = new CustomAdapter();

    listview.setAdapter(customAdapter);

}

class CustomAdapter extends BaseAdapter{


    @Override
    public int getCount() {
        return Imagens.length;
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        convertView = getLayoutInflater().inflate(R.layout.customlistview, null);
        ImageView imageView = (ImageView) convertView.findViewById(R.id.imageView);
        TextView textViewnome = (TextView) convertView.findViewById(R.id.textViewnome);
        TextView textViewtime = (TextView) convertView.findViewById(R.id.textViewtime);
        TextView textViewgols = (TextView) convertView.findViewById(R.id.textViewgols);

        imageView.setImageResource(Imagens[position]);
        textViewnome.setText(Nomes[position]);
        textViewtime.setText(Times[position]);
       textViewgols.setText(Gols[position]);


        return convertView;
    }
}
 

Tentei usar esse metodo, mas da erro, desculpem qualquer erro.

listview.setOnClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            
        }
    });
public class artilheiros extends AppCompatActivity {

int [] Imagens = {R.drawable.arg, R.drawable.bolivia, R.drawable.brasil, R.drawable.chile,
          R.drawable.colombia, R.drawable.chile, R.drawable.paraguai, R.drawable.uruguai,
          R.drawable.arg, R.drawable.bolivia, R.drawable.brasil, R.drawable.chile,
          R.drawable.colombia, R.drawable.chile, R.drawable.paraguai};

String [] Nomes = {"ART 1", "ART 2", "ART 3", "ART 4", "ART 5", "ART 6", "ART 7", "ART 8",
                    "ART 9", "ART 10", "ART 11", "ART 12", "ART 13", "ART 14", "ART 15"};

String [] Times = {"TIME 1", "TIME 2", "TIME 3", "TIME 4", "TIME 5", "TIME 6", "TIME 7",
        "TIME 8", "TIME 9", "TIME 10", "TIME 11", "TIME 12", "TIME 13", "TIME 14", "TIME 15"};

String [] Gols = {"999 gols", "999 gols", "999 gols", "999 gols", "999 gols", "999 gols", "999 gols",
       "999 gols", "999 gols", "999 gols", "999 gols", "999 gols", "999 gols", "999 gols", "999 gols"};



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

    ListView listview = findViewById(R.id.listviewart);

    CustomAdapter customAdapter = new CustomAdapter();

    listview.setAdapter(customAdapter);

}

class CustomAdapter extends BaseAdapter{


    @Override
    public int getCount() {
        return Imagens.length;
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        convertView = getLayoutInflater().inflate(R.layout.customlistview, null);
        ImageView imageView = (ImageView) convertView.findViewById(R.id.imageView);
        TextView textViewnome = (TextView) convertView.findViewById(R.id.textViewnome);
        TextView textViewtime = (TextView) convertView.findViewById(R.id.textViewtime);
        TextView textViewgols = (TextView) convertView.findViewById(R.id.textViewgols);

        imageView.setImageResource(Imagens[position]);
        textViewnome.setText(Nomes[position]);
        textViewtime.setText(Times[position]);
       textViewgols.setText(Gols[position]);


        return convertView;
    }
}
 

Eu usei esse o metodo abaixo, porém todos os itens da lista abrem a mesma activity...

  int position = getIntent().getIntExtra("a", 0);

    listview.setOnItemClickListener(new AdapterView.OnItemClickListener() { 

        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            artilheiros a1 = (artilheiros) listview.getItemAtPosition(0);
            Intent it = new Intent(artilheiros.this, campeoes.class);
            it.putExtra("a1", position);
            startActivity(it);
        }
    });
adicionou 312 caracteres ao conteúdo
Fonte Link
vitu
  • 11
  • 2

Tentei usar esse metodo, mas da erro, desculpem qualquer erro.

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

Tentei usar esse metodo, mas da erro, desculpem qualquer erro.

listview.setOnClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            
        }
    });
Fonte Link
vitu
  • 11
  • 2

Abrir activity ao clicar em um item em uma custom listview

Criei uma custom listview, está tudo certo, já tentei aqui mas não da certo, queria implementar o click em um item, porém como é custom listview talvez seja algo diferente, sou iniciante, queria uma ajuda :/

public class artilheiros extends AppCompatActivity {

int [] Imagens = {R.drawable.arg, R.drawable.bolivia, R.drawable.brasil, R.drawable.chile,
          R.drawable.colombia, R.drawable.chile, R.drawable.paraguai, R.drawable.uruguai,
          R.drawable.arg, R.drawable.bolivia, R.drawable.brasil, R.drawable.chile,
          R.drawable.colombia, R.drawable.chile, R.drawable.paraguai};

String [] Nomes = {"ART 1", "ART 2", "ART 3", "ART 4", "ART 5", "ART 6", "ART 7", "ART 8",
                    "ART 9", "ART 10", "ART 11", "ART 12", "ART 13", "ART 14", "ART 15"};

String [] Times = {"TIME 1", "TIME 2", "TIME 3", "TIME 4", "TIME 5", "TIME 6", "TIME 7",
        "TIME 8", "TIME 9", "TIME 10", "TIME 11", "TIME 12", "TIME 13", "TIME 14", "TIME 15"};

String [] Gols = {"999 gols", "999 gols", "999 gols", "999 gols", "999 gols", "999 gols", "999 gols", "999 gols", "999 gols", "999 gols", "999 gols", "999 gols", "999 gols", "999 gols", "999 gols"};

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

    ListView listview = findViewById(R.id.listviewart);

    CustomAdapter customAdapter = new CustomAdapter();

    listview.setAdapter(customAdapter);

}

class CustomAdapter extends BaseAdapter{


    @Override
    public int getCount() {
        return Imagens.length;
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        convertView = getLayoutInflater().inflate(R.layout.customlistview, null);
        ImageView imageView = (ImageView) convertView.findViewById(R.id.imageView);
        TextView textViewnome = (TextView) convertView.findViewById(R.id.textViewnome);
        TextView textViewtime = (TextView) convertView.findViewById(R.id.textViewtime);
        TextView textViewgols = (TextView) convertView.findViewById(R.id.textViewgols);

        imageView.setImageResource(Imagens[position]);
        textViewnome.setText(Nomes[position]);
        textViewtime.setText(Times[position]);
       textViewgols.setText(Gols[position]);


        return convertView;
    }
}
 

}