带有JSON和自定义适配器的字符串数组

时间:2014-06-07 05:52:07

标签: java android json

早上好,我正在从我的MySQL数据库中检索一些值,因为我想将它们显示到带有自定义适配器的ListView中。我有这个代码。

            for(int i=0; i<jsonArray.length();i++) {
                ogge = new Ogge();
                json = jsonArray.getJSONObject(i);
                ogge.title = json.getString("Title");
                ogge.array = new String[] {json.getString("field1"), json.getString("field2"), json.getString("field3"), json.getString("field4"), json.getString("field5"), json.getString("field6")};
                ogge.adapter = Ogge.MY_CUSTOM;     
                list.add(ogge);
            }

这是正确的,因为值放在Ogge类的数组中。这是适配器

    case Ogge.MY_CUSTOM:
        view = inflater.inflate(R.layout.custom, null);
        textView = (TextView)view.findViewById(R.id.textView1);
        textView2 = (TextView)view.findViewById(R.id.textView2);
        textView3 = (TextView)view.findViewById(R.id.textView3);
        textView.setText(Html.fromHtml(ogge.title));
        textView2.setText(MyJsonClass.DATABASE_FIELD[position]);
        textView3.setText(ogge.array[position]);

        break;

问题是如下:当我打开我的应用程序时,我只看到ogge.array的第一个和第二个值,但我想显示所有。如果我进入适配器以获取数组中的值,则值全部存储到数组中,因此数组是正确的,但是,为什么我只显示前两个值而不是全部?

适配器完整代码

public MyCustomAdapter(Context context, int resource, ArrayList<Ogge> list) {   
        super(context, resource, list);
        // TODO Auto-generated constructor stub
        this.context = context;
        this.list = list;
    }

    @SuppressLint("CutPasteId")
    @Override
    public View getView(int position, View view, ViewGroup parent) {
        inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        final Ogge ogge = list.get(position);

        switch(ogge.adapter) {

        case Ogge.MY_CUSTOM:
       view = inflater.inflate(R.layout.custom, null);
        textView = (TextView)view.findViewById(R.id.textView1);
        textView2 = (TextView)view.findViewById(R.id.textView2);
        textView3 = (TextView)view.findViewById(R.id.textView3);
        textView.setText(Html.fromHtml(ogge.title));
        textView2.setText(MyJsonClass.DATABASE_FIELD[position]);
        textView3.setText(ogge.array[position]);

        break;
        }
        return view;
    }

    @Override
    public boolean isEnabled(int position) {
        return false;
    }   
}

0 个答案:

没有答案