【问题标题】:select from parse not show the values in list view android从解析中选择不显示列表视图android中的值
【发布时间】:2014-05-16 13:23:16
【问题描述】:

我有这段代码,它只能从解析所有数据中选择,在它成功后,我希望在我为它制作的视图中显示这些数据,当我设置所有文本视图时,它会在我的应用程序中显示:

这是我的代码:

 protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_sharing_board);

    Parse.initialize(this, "******", "******");

    //Set up the listview
    ArrayList<String> sharingList = new ArrayList<String>();
    //Create and populate an ArrayList of objects from parse
    listAdapter = new ArrayAdapter<View>(this, android.R.layout.simple_list_item_1);
    ListView SharingListView = (ListView)findViewById(R.id.listView1);
    SharingListView.setAdapter(listAdapter);

    final ParseQuery query = new ParseQuery("SharingBoard");
    Inflater = (LayoutInflater)this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

    query.findInBackground(new FindCallback<ParseObject>()
    {
        public void done(List<ParseObject> objects, ParseException e)
        {
            if (e == null)
            {
                for (int i = 0; i < objects.size(); i++)
                {
                    Object object = objects.get(i);

                    String name = ((ParseObject) object).getString("Name").toString();
                    String part = ((ParseObject) object).getString("Part").toString();
                    String desc = ((ParseObject) object).getString("Desc").toString();

                    View view = Inflater.inflate(R.layout.item_list, null);

                    // Add the name view
                    TextView nameTextView = (TextView) view.findViewById(R.id.lblName);
                    nameTextView.setText(name);

                    // Add the part view
                    TextView partTextView = (TextView) view.findViewById(R.id.lblPart);
                    partTextView.setText(part);

                    // Add the desc view
                    TextView descTextView = (TextView) view.findViewById(R.id.lblDesc);
                    descTextView.setText(desc);

                    listAdapter.add(view);
                }
            }
            else
            {
                Log.d("error", e.toString());
                Toast.makeText(getApplicationContext(), "Error", Toast.LENGTH_LONG).show();
            }
        }
    });

我做错了什么? 谢谢...

【问题讨论】:

  • 您不会将视图添加到适配器。

标签: android listview parse-platform android-inflate


【解决方案1】:

您不应该在解析数据时将视图添加到 ListView

如果列表中的每个单元格都只有文本,那么最简单的解决方案是here

如果你需要一个更复杂的单元格,一个解决方案是有一个布局资源来布局一个单元格,将你解析的数据放入一个数组中,并有一个 ArrayAdapter 的子类覆盖 getView() 来放置每个项目放入一个单元格的相应视图中。有一个很好的教程here

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-10-23
    • 1970-01-01
    • 1970-01-01
    • 2013-09-21
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多