ListView setOnItemClickListener in a fragment

0

My setOnItemClickListener does not work in the fragment, when I click the listview item in the app to work, I am using a custom adapter, it follows code:

public void criarListagem() {
    List<Curso> cursos = todosOsCursos();
    AdapterCursosPersonalizado adapter = new AdapterCursosPersonalizado(cursos, this);
    lista.setAdapter(adapter);

    lista.setOnItemClickListener(new AdapterView.OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> av, View v, int pos, long id) {

            Toast.makeText(getActivity(), "teste0", Toast.LENGTH_LONG).show();

            select = id2[pos];
            nome2 = nome[pos];
            telefone2 = telefone[pos];
            celular2 = celular[pos];
            renda2 = renda[pos];
            limite2 = limite[pos];
            status2 = status[pos];
            bandeira2 = bandeira[pos];

            Intent it = new Intent(getActivity(), info_cliente.class);
            it.putExtra("id", select);
            it.putExtra("nome", nome2);
            it.putExtra("telefone", telefone2);
            it.putExtra("celular",celular2);
            it.putExtra("renda", renda2);
            it.putExtra("limite", limite2);
            it.putExtra("status", status2);
            it.putExtra("bandeira", bandeira2);

            startActivity(it);
        }
    });

LongClick worked, but not this.

xml:

<FrameLayout xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/fragment_container_1"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:descendantFocusability="blocksDescendants">

    <TextView
        android:id="@+id/textView18"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Lista de Clientes"
        android:textSize="16sp"
        android:textStyle="bold"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="10dp" />

    <android.support.design.widget.FloatingActionButton
        android:id="@+id/floatingActionButton"
        android:layout_width="70dp"
        android:layout_height="70dp"
        android:layout_alignParentBottom="true"
        android:layout_alignRight="@+id/clientes"
        android:layout_marginBottom="60dp"
        android:clickable="true"
        app:backgroundTint="@android:color/background_dark"
        app:fabSize="normal"
        app:srcCompat="@drawable/mais"/>

    <ListView
        android:id="@+id/clientes"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_alignParentBottom="true"
        android:layout_below="@+id/textView18"
        android:longClickable="true"
        android:layout_marginBottom="50dp"
        android:layout_marginLeft="10dp"
        android:layout_marginRight="10dp"
        android:layout_marginTop="15dp" />

</RelativeLayout>


</FrameLayout>

Adapter:

public class AdapterCursosPersonalizado extends BaseAdapter {

private final List<Curso> cursos;
private final clientes act;

public AdapterCursosPersonalizado(List<Curso> cursos, clientes act) {
    this.cursos = cursos;
    this.act = act;
}

@Override
public int getCount() {
    return cursos.size();
}

@Override
public Object getItem(int position) {
    return cursos.get(position);
}

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

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    View view = act.getActivity().getLayoutInflater().inflate(R.layout.lista_curso_personalizada, parent, false);

    Curso curso = cursos.get(position);

    TextView nome = (TextView)
            view.findViewById(R.id.lista_personalizada_nome);
    TextView telefone = (TextView)
            view.findViewById(R.id.lista_personalizada_telefone);
    TextView celular = (TextView)
            view.findViewById(R.id.lista_personalizada_celular);
    TextView renda = (TextView)
            view.findViewById(R.id.lista_personalizada_renda);
    TextView limite = (TextView)
            view.findViewById(R.id.lista_personalizada_limite);
    TextView status = (TextView)
            view.findViewById(R.id.lista_personalizada_status);
    TextView bandeira = (TextView)
            view.findViewById(R.id.lista_personalizada_bandeira);
    TextView id = (TextView)
            view.findViewById(R.id.lista_personalizada_id);

    nome.setText(curso.getNome());
    telefone.setText(curso.getTelefone());
    celular.setText(curso.getCelular());
    renda.setText(curso.getRenda());
    limite.setText(curso.getLimite());
    status.setText(curso.getStatus());
    bandeira.setText(curso.getBandeira());
    id.setText(curso.getId());

    /*
    if(curso.getStatus().contains("Devendo")){

        view.setBackgroundColor(Color.parseColor("#FA8072"));

    }else{

        view.setBackgroundColor(Color.parseColor("#90EE90"));

    }*/

    return view;
}

}

    
asked by anonymous 01.02.2018 / 19:31

0 answers