重新绘制/更新基础适配器?
我正在做一个应用程序,我需要一个列表视图,其中每行都有一些文本和一个图像按钮(只是为了删除每个按钮中具有相同图像的该行)。在网上冲浪我得到了这个代码 http://www.codemobiles.com/论坛/viewtopic.php?t=876。由于该代码还有图像,因此我删除了图像的代码。一切都很顺利,但我试图动态地列出清单,但我做不到。我创建了一个数组列表并修改了该代码以能够添加我的数组列表,因此现在我可以添加或删除项目(并且该部分有效,因为我尝试仅运行这部分代码)但我无法“重新绘制” 。我的想法是,如果我有这个适配器并且可以工作,那么让我们添加或删除一个项目并调用该方法,但是如果我再次创建一个创建者的调用者,正如您在 onCreate 方法中看到的那样:
adap = new EfficientAdapter(this);
setListAdapter(adap);
没有错误,但没有新闻。我该怎么做呢?我还注意到,如果我有 0 行,因为在我返回一个空字符串数组中没有错误
public Object getItem(int position)
,并且在这个方法中:
public int getCount()
我返回 0 但我有一行。我该如何解决这个问题?
我的这两种方法的代码是:
public int getCount() {
// TODO Auto-generated method stub
// My arraylist is data2. Because of I didn't know how to do
//an arraylist of n elements with 3 subelements in each element and then convert
// it to an array, I add every subelement one after one and then I don't mix subelements.
String [] cambio = (String[]) data2.toArray(new String[data2.size()]);
if (cambio.length == 0){
return 0;
}
String[] cambio2 = new String[cambio.length/3];
int j = 0;
for(int i=0;i<(cambio.length/3);i=i+3){
//that's because I need an output of a single string array and
// I need my subelements in this order
cambio2[j] = cambio[i+1] + " " + cambio[i+2] + " " + cambio[i];
j++;
}
return cambio2.length;
//return data.length;
}
@Override
public Object getItem(int position) {
// TODO Auto-generated method stub
String [] cambio = (String[]) data2.toArray(new String[data2.size()]);
if (cambio.length == 0){
return cambio;
}
String[] cambio2 = new String[cambio.length/3];
int j = 0;
for(int i=0;i<(cambio.length/3);i=i+3){
cambio2[j] = cambio[i+1] + " " + cambio[i+2] + " " + cambio[i];
j++;
}
return cambio2[position];
//return data[position];
}
提前非常感谢。
I'm doing an application where I need to have a listview where each row has some text and an imagebutton (just for delete that row with the same image in every button). Surfing on the net I have got this code http://www.codemobiles.com/forum/viewtopic.php?t=876. Because of this code has also an image, I deleted the code for the image. All is working well but I'm trying to do the list dinamically and I can't. I have created an arraylist and modified that code to being able for adding my arraylist so now I can add or delete items (and that piece works because I have tried to run only this part of code) but I'm unable to "repaint". My idea was if I have this adapter and works, let's add or delete an item and recall the method but if I create again a caller to the creator as you can see onCreate method:
adap = new EfficientAdapter(this);
setListAdapter(adap);
There's no error but there's no news. How can I do it? Also I noticed that if I have 0 rows for not having an error in the
public Object getItem(int position)
I return an empty string array and in this method:
public int getCount()
I return 0 but then I have a row. how can I fix that?
My code for this 2 methods are:
public int getCount() {
// TODO Auto-generated method stub
// My arraylist is data2. Because of I didn't know how to do
//an arraylist of n elements with 3 subelements in each element and then convert
// it to an array, I add every subelement one after one and then I don't mix subelements.
String [] cambio = (String[]) data2.toArray(new String[data2.size()]);
if (cambio.length == 0){
return 0;
}
String[] cambio2 = new String[cambio.length/3];
int j = 0;
for(int i=0;i<(cambio.length/3);i=i+3){
//that's because I need an output of a single string array and
// I need my subelements in this order
cambio2[j] = cambio[i+1] + " " + cambio[i+2] + " " + cambio[i];
j++;
}
return cambio2.length;
//return data.length;
}
@Override
public Object getItem(int position) {
// TODO Auto-generated method stub
String [] cambio = (String[]) data2.toArray(new String[data2.size()]);
if (cambio.length == 0){
return cambio;
}
String[] cambio2 = new String[cambio.length/3];
int j = 0;
for(int i=0;i<(cambio.length/3);i=i+3){
cambio2[j] = cambio[i+1] + " " + cambio[i+2] + " " + cambio[i];
j++;
}
return cambio2[position];
//return data[position];
}
Thank you very much in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论