0

我正在尝试在两个活动中使用片段。此片段有一个带有 onClickItemListener 的 ListView,但我需要在活动中更改此侦听器的行为。有可能吗?

我在这里插入片段代码:

分段

    @Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
view = inflater.inflate(R.layout.fragment_my_sharing_tools, container, false);
initList();
return view;
}

private void initList() {
list = (ListView) view.findViewById(R.id.ListView_llista);
list.setAdapter(new HandlerList(view.getContext(), R.layout.fila_llista_entrada, toolsList) {
    @Override
    public void onEntrada(Object entrada, View view) {
    if (entrada != null) {
        TextView nom = (TextView) view.findViewById(R.id.resultatsNomTxtVw);
        if (nom != null)
        nom.setText(((Tools) entrada).getNom());

        TextView descripcio = (TextView) view.findViewById(R.id.resultatsDistanciaTxtVw);
        if (descripcio != null)
        descripcio.setText(((Tools) entrada).getDescripcio());

        ImageView imagen_entrada = (ImageView) view.findViewById(R.id.imageToolIV);
        if (imagen_entrada != null)
        // imagen_entrada.setImageResource(((Llista_entrada)
        // entrada).get_idImagen());
        imagen_entrada.setImageBitmap(((Tools) entrada).getImage());
    }
    }
});
list.setOnItemClickListener(new OnItemClickListener() {
    @Override
    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
    Object o = list.getItemAtPosition(position);
    Tools tool = (Tools) o;
    Intent intent = new Intent(view.getContext(), AfegirToolActivity.class);
    intent.putExtra("com.sharingtools.TabMyToolsFragment", tool);
    Toast.makeText(( view.getContext()), tool.getNom(), Toast.LENGTH_SHORT).show();
    (view.getContext()).startActivity(intent);
    }
});
list.setOnItemLongClickListener(new OnItemLongClickListener() {
    @Override
    public boolean onItemLongClick(AdapterView<?> parent, View view, final int position, long id) {
    Object o = list.getItemAtPosition(position);
    final Tools tool = (Tools) o;
    final ImageView erase = (ImageView) view.findViewById(R.id.toolRowEraseIcon);
    erase.setVisibility(View.VISIBLE);
    erase.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
        ParseQuery qry = new ParseQuery("Tool");
        try {
            ParseObject po = qry.get(tool.getId());
            po.delete();
            toolsList.remove(position);
            erase.setVisibility(View.INVISIBLE);
            ((HandlerList) list.getAdapter()).notifyDataSetChanged();
        } catch (ParseException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        }
    });
    return true;
    }
}); 
}
4

0 回答 0