-1

i have this code which onlt select from parse all the data, afer it succedd i wish to show this data in a view i made for it, when i set all the text views it shows this in my app :

enter image description here

this is my code :

 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();
            }
        }
    });

what do i do wrong ? thanks...

spinker
  • 298
  • 4
  • 20

1 Answers1

1

You shouldn't add views to a ListView as you parse data.

If each cell in the list is only text, then the simplest solution is here.

If you need a more complex cell, one solution is to have a layout resource that lays out a cell, put your parsed data into an array, and have a subclass of ArrayAdapter override getView() to place the content of each item into the corresponding views of a cell. There's a good tutorial here.

Community
  • 1
  • 1
bkDJ
  • 750
  • 7
  • 10