在父单击的可扩展列表中,我有一个孩子,其中有3个文本视图,例如,当我单击不同的文本视图时,我想触发其他事件.
for text vIEw 1 output is hellofor text vIEw 2 output is hifor text vIEw 3 output is heya
解决方法:
正如eDWin所说,您可以制作一个Costum适配器.您可以在其中在每个VIEw上使用setonClickListner()方法.就像我在这里一样
class CustomAdapter extends ArrayAdapter<Contact> { LayoutInflater inflater=(LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE); public CustomAdapter(Context context, int textVIEwResourceID, ArrayList<Contact> strings) { //let androID do the initializing :) super(context, textVIEwResourceID, strings); } //class for caching the vIEws in a row private class VIEwHolder { TextVIEw ID,name,phn_no; } VIEwHolder vIEwHolder; @OverrIDe public VIEw getVIEw(int position, VIEw convertVIEw, VIEwGroup parent) { if(convertVIEw==null) { //inflate the custom layout convertVIEw=inflater.inflate(R.layout.activity_main, null); vIEwHolder=new VIEwHolder(); //cache the vIEws vIEwHolder.ID=(TextVIEw) convertVIEw.findVIEwByID(R.ID.contact_ID_txt); vIEwHolder.name=(TextVIEw) convertVIEw.findVIEwByID(R.ID.contact_name_txt); vIEwHolder.phn_no=(TextVIEw) convertVIEw.findVIEwByID(R.ID.contact_ph_no_txt); vIEwHolder.ID.setonClickListener(new VIEw.OnClickListener() { @OverrIDe public voID onClick(VIEw v) { Toast.makeText(getApplicationContext(), "Hi!!", Toast.LENGTH_SHORT).show(); } }); vIEwHolder.name.setonClickListener(new VIEw.OnClickListener() { @OverrIDe public voID onClick(VIEw v) { // Todo auto-generated method stub Toast.makeText(getApplicationContext(), "Hello!!", Toast.LENGTH_SHORT).show(); } }); vIEwHolder.phn_no.setonClickListener(new VIEw.OnClickListener() { @OverrIDe public voID onClick(VIEw v) { // Todo auto-generated method stub Toast.makeText(getApplicationContext(), "heya!!!", Toast.LENGTH_SHORT).show(); } }); //link the cached vIEws to the convertvIEw convertVIEw.setTag(vIEwHolder); } else vIEwHolder=(VIEwHolder) convertVIEw.getTag(); //set the data to be displayed vIEwHolder.ID.setText(contacts.get(position).get_ID()+""); vIEwHolder.name.setText(contacts.get(position).get_name()); vIEwHolder.phn_no.setText(contacts.get(position).get_phn_no()); //return the vIEw to be displayed return convertVIEw; } }
总结 以上是内存溢出为你收集整理的如何在Android的可扩展列表视图中的子点击部分触发事件全部内容,希望文章能够帮你解决如何在Android的可扩展列表视图中的子点击部分触发事件所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)