Question

When I click in an item of the List the method OnItemClick is not ben called. I'm trying to call another activity to show more information about that "AnaliseEstrutural". What will be in the List is the value Brunton or Clar defined for ehBrunton . Then when the user clicks on a item it will apear the oter information about that "AnaliseEstrutural". But it's not passing by the method.

here is the code:

public class AnalisesPonto extends ListFragment implements OnItemClickListener{

private ArrayList<AnaliseEstrutural> analises;
AnalisesDAO andao;
String idPonto;
private View view;
private ListView analisesList;
private AnalisesAdapter analisesAdapter;
private boolean ehBrunton;
private Intent i;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setRetainInstance(true);

    idPonto = getArguments().getString("id");

    andao = new AnalisesDAO(getActivity().getApplicationContext());
    analises = andao.relatorioAnalises(idPonto);
    ehBrunton = true;
    i = new Intent(getActivity().getApplicationContext(), DadosAnalises.class);
}

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {


    view = inflater.inflate(R.layout.analises_ponto_layout, null);

    analisesList = (ListView) view.findViewById(android.R.id.list);

    analisesAdapter = new AnalisesAdapter(getActivity().getApplicationContext(), true);

    for (int i = 0; i < analises.size(); i++) {
        analisesAdapter.add(analises.get(i));
    }

    analisesList.setAdapter(analisesAdapter);

    ViewGroup parent = (ViewGroup) analisesList.getParent();
    parent.removeView(analisesList);
    analisesList.setOnItemClickListener(new OnItemClickListener()
    {
        @Override public void onItemClick(AdapterView<?> arg0, View arg1,int position, long arg3)
        {           
            Bundle extra = new Bundle();
            extra.putBoolean("radio", ehBrunton);
            extra.putString("tipo_est", analises.get(position).getTipo());
            extra.putString("codigo", analises.get(position).getCodigo());
            if(ehBrunton) {
                extra.putString("brun_clar", analises.get(position).getBrunton());
            } else {
                extra.putString("brun_clar", analises.get(position).getClar());
            }
            extra.putString("azimute", analises.get(position).getAzimute());
            extra.putString("direcao", analises.get(position).getDirecao());
            extra.putString("quadrante", analises.get(position).getQuadrante());
            extra.putString("sentido", analises.get(position).getSentido());
            extra.putString("descricao",analises.get(position).getDescricao());
            extra.putString("mergulho", analises.get(position).getMergulho());
            extra.putString("familia", analises.get(position).getFamilia());
            i.putExtra("analise", extra);
            startActivity(i);
        }
    });  




    return analisesList;
}
 }

The layout from the List:

    <?xml version="1.0" encoding="utf-8"?>
   <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="fill_parent"
      android:layout_height="fill_parent"
      android:orientation="vertical" >

          <ListView
             android:id="@android:id/list"
             android:layout_width="fill_parent"
             android:layout_height="match_parent" >
         </ListView>
    </LinearLayout>

And here is the Layout of the Element of the List

  <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical" >

       <TextView
          android:id="@+id/med_angular"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content" />
    </LinearLayout>
Was it helpful?

Solution

[RESOLVED] Put the method analisesList.setOnItemClickListener(new OnItemClickListener() inside onActivityCreated instead onCrateView

 @Override
    public void onActivityCreated(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onActivityCreated(savedInstanceState);
        analisesList.setOnItemClickListener(new OnItemClickListener()
        {
            @Override public void onItemClick(AdapterView<?> arg0, View arg1,int position, long arg3)
            {           
                Bundle extra = new Bundle();
                extra.putBoolean("radio", ehBrunton);
                extra.putString("tipo_est", analises.get(position).getTipo());
                extra.putString("codigo", analises.get(position).getCodigo());
                if(ehBrunton) {
                    extra.putString("brun_clar", analises.get(position).getBrunton());
                } else {
                    extra.putString("brun_clar", analises.get(position).getClar());
                }
                extra.putString("azimute", analises.get(position).getAzimute());

                extra.putString("direcao", analises.get(position).getDirecao());
                extra.putString("quadrante", analises.get(position).getQuadrante());
                extra.putString("sentido", analises.get(position).getSentido());
                extra.putString("descricao",analises.get(position).getDescricao());
                extra.putString("mergulho", analises.get(position).getMergulho());
                extra.putString("familia", analises.get(position).getFamilia());
                i.putExtra("analise", extra);
                startActivity(i);
            }
        });
    }

OTHER TIPS

What is this removeView for?

parent.removeView(analisesList);

Also shouldn't you be returning the whole view in onCreateView instead of analisesList?

I guess doing the following fill fix the issues

  1. remove "parent.removeView(analisesList);"
  2. return analisesList;
  3. remove implements onOtemClickListener (You are creating an inner annonymous class as mentioned by Raghunandan)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top