Como deixar OnClick na função de atividade de chamada de adaptador do ListView
Eu tenho um aplicativo Android com um ListView nele, o ListView irá configurar bem, mas agora eu quero uma imagem no ListView para ser clicável. Eu faço isso usando 2 classes, a classe Activity (pai) e um ArrayAdapter para preencher a lista. No ArrayAdapter eu implemento um OnClickListener para a imagem na lista que eu quero ser clicável.
Até agora tudo funciona.
Mas agora eu quero executar uma função da classe de atividade quando o onClick, para a imagem na lista, é executado, mas eu não sei como. Abaixo estão as 2 classes que eu uso.
Primeiro a classe Activity:
<code>public class parent_class extends Activity implements OnClickListener, OnItemClickListener { child_class_list myList; ListView myListView; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); // setup the Homelist data myList = new child_class_list (this, Group_Names, Group_Dates); myListView = (ListView) findViewById(R.id.list); // set the HomeList myListView.setAdapter( myList ); myListView.setOnItemClickListener(this); } void function_to_run() { // I want to run this function from the LiscView Onclick } public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) { // do something } } </code>
E o ArrayAdapter de onde eu quero chamar uma função da classe Activity:
<code>public class child_class_list extends ArrayAdapter<String> { // private private final Context context; private String[] mName; private String[] mDate; public child_class_list (Context context, String[] Name, String[] Date) { super(context, R.layout.l_home, GroupName); this.context = context; this.mName = Name; this.mDate = Date; } @Override public View getView(int position, View convertView, ViewGroup parent) { LayoutInflater inflater = (LayoutInflater) context .getSystemService(Context.LAYOUT_INFLATER_SERVICE); View rowView = inflater.inflate(R.layout.l_home, parent, false); ImageView selectable_image = (ImageView) rowView.findViewById(R.id.l_selectable_image); selectable_image.setOnClickListener(new OnClickListener() { public void onClick(View v) { // I want to run the function_to_run() function from the parant class here } } ); // get the textID's TextView tvName = (TextView) rowView.findViewById(R.id.l_name); TextView tvDate = (TextView) rowView.findViewById(R.id.l_date); // set the text tvName.setText (mName[position]); tvDate.setText (mDate[position]); return rowView; } } </code>
Se alguém souber como executar a função na classe de atividade a partir do arrayadapter ou como definir a imagem onClickListener na classe de atividade, eu aprimo seriamente a ajuda.