2

当我单击 List 的一个项目时,不会调用 OnItemClick 方法。我正在尝试调用另一个活动来显示有关“AnalyseEstrutural”的更多信息。列表中将包含为 ehBrunton 定义的 Brunton 或 Clar 值。然后,当用户单击一个项目时,它将显示有关该“AnaliseEstrutural”的其他信息。但它不是通过方法传递的。

这是代码:

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;
}
 }

列表中的布局:

    <?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>

这是列表元素的布局

  <?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>
4

2 回答 2

4

[已解决]将方法放在analisesList.setOnItemClickListener(new OnItemClickListener() 里面 onActivityCreatedonCrateView

 @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);
            }
        });
    }
于 2013-07-16T17:49:03.497 回答
0

这个 removeView 是干什么用的?

parent.removeView(analisesList);

你也不应该在 onCreateView 而不是 analisesList 中返回整个视图吗?

我猜做以下填充可以解决问题

  1. 删除“parent.removeView(analisesList);”
  2. 返回分析列表;
  3. 删除实现 onOtemClickListener (您正在创建 Raghunandan 提到的内部匿名类)
于 2013-07-16T17:12:31.217 回答