我有一个带有getVIEw的类,它处理onclick侦听器,该侦听器将删除ArrayList中位于活动扩展的另一个类中的数据,问题是它返回了一个空指针.
这是我处理ArrayList的活动
public ArrayList<String> imagesfilename = new ArrayList<String>();public ArrayList<HashMap<String, String>> myList;//method for deleting data in array List and will going to use in another classpublic voID deletefile(int i){ imagesfilename.remove(i); myList.remove(i); adapter.notifyDataSetInvalIDated();}
这是我的类,其中包含一个getVIEw()并将使用在活动中声明的方法
Activity activity = new Activity();@OverrIDepublic VIEw getVIEw(final int position, VIEw convertVIEw, VIEwGroup parent) { LayoutInflater inflater = LayoutInflater.from(context); VIEw rowVIEw = null; try{ rowVIEw = inflater.inflate(resource, null, true); TextVIEw textVIEwTitle = (TextVIEw) rowVIEw.findVIEwByID(to[0]); EditText textVIEwSubTitle = (EditText) rowVIEw.findVIEwByID(to[1]); TextVIEw textVIEwSubTitle1 = (TextVIEw) rowVIEw.findVIEwByID(to[2]); TextVIEw textVIEwSubTitle2 = (TextVIEw) rowVIEw.findVIEwByID(to[3]); final TextVIEw textVIEwSubTitle3 = (TextVIEw) rowVIEw.findVIEwByID(to[4]); TextVIEw textVIEwID = (TextVIEw) rowVIEw.findVIEwByID(to[5]); final String ID = textVIEwID.getText().toString(); textVIEwSubTitle3.setonClickListener(new OnClickListener() { @OverrIDe public voID onClick(VIEw vIEw) { // Todo auto-generated method stub activity.deletefile(ID);//here is my method in my Activiy } });
当我在同一活动中使用该方法时,它将起作用.但是,当我将它用于另一个类时,它将返回indexoutofbounds.
解决方法:
我终于弄清楚了,我所需要的就是将我的Activity和Class合并在一个页面中,以便Class能够访问我的数组列表.
总结以上是内存溢出为你收集整理的android-如何从另一个活动中删除数组列表中的数据全部内容,希望文章能够帮你解决android-如何从另一个活动中删除数组列表中的数据所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)