2012-02-28 67 views
0

对不起,我的英语。我有我自己的ArrayAdapter列表活动。我的问题是:当我将数据提交到Web服务时,数据被添加到ArrayList。这里一切都很正常。 Nexus和Android OS 4.0列出了数据,但其他手机和2.3.3不列出数据。一切正常,我没有收到任何错误。Android自己的阵列适配器

我不知道什么是问题。使用Nexus(OS 4.0)编程列表数据,但未在2.3.3中列出。

  • 我的主要活动类扩展ListActivity
    • 公共静态的ArrayList freqzo;静态MobileArrayAdapter freqz;
    • freqzo = new ArrayList(); freqz = new MobileArrayAdapter(this,freqzo);
    • this.setListAdapter(freqz); ListView lv = getListView();
    • lv.setTextFilterEnabled(true); //和我的填充数组列表部分:if(store
    • instanceof Vector){Object [] arr =((Vector)store).toArray();对于
    • (int i = 0; i < arr.length; i ++){freqzo.add((String)arr [i] .toString()); }

我的移动适配器类:

public class MobileArrayAdapter extends ArrayAdapter<String> { 

    private final Context context; 
    private final ArrayList<String> values; 

    public MobileArrayAdapter(Context context, ArrayList<String> values) { 
     super(context, R.layout.listlayout, values); 
     this.context = context; 
     this.values = values; 
    } 

    @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.listlayout, parent, false); 
     TextView textView = (TextView) rowView.findViewById(R.id.label); 
     ImageView imageView = (ImageView) rowView.findViewById(R.id.logo); 

     String s = values.get(position); 
     Log.d("Liste", "Liste " + values.get(position)); 
     if (s != null && !s.equals("")) { 
      textView.setText(s); 
     } 

     // Change icon based on name 
     // String s = values[position]; 

     return rowView; 
    } 
} 

回答

1

也许尽显你的名单后,你应该叫adapter.notifyDataSetChanged()

+0

感谢我的freand它的工作。 – 2012-02-28 14:54:06

0

那件是坏:

LayoutInflater inflater = (LayoutInflater) context 
     .getSystemService(Context.LAYOUT_INFLATER_SERVICE); 

    View rowView = inflater.inflate(R.layout.listlayout, parent, false); 

第一,你不使用,是由适配器为您创建的视图,但始终创建​​一个新的。 Java机器会清理过多的对象,但需要大量的时间。其次,ArrayAdapter可以完成所有工作。看here

相关问题