无法检索数据并在列表视图中显示

时间:2016-03-18 05:04:54

标签: android listview parsing fetch

这是我的代码:

public class MenuActivity extends AppCompatActivity {
ListView listview;
ArrayAdapter adapter;
ArrayList<String> mylist;
String name;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_menu);

    listview = (ListView) findViewById(R.id.listview);
    mylist = new ArrayList<>();

    parseDataFetch();


}

public void parseDataFetch()
{
    if (FragmentA.item == "first") {

        ParseQuery<ParseObject> query = ParseQuery.getQuery("menu");
        query.whereEqualTo("type", "testRow");
        query.findInBackground(new FindCallback<ParseObject>() {
            public void done(List<ParseObject> nameList, ParseException e)
            {
                if (e == null) {
                    for (ParseObject object : nameList) {
                         name = object.getString("itemName");
                        mylist.add(name);
                        adapter = new ArrayAdapter<>(MenuActivity.this, R.layout.activity_menu, mylist);
                    }
                    listview.setAdapter(adapter);
                } else {
                    Toast.makeText(getApplicationContext(), "Error", Toast.LENGTH_SHORT).show();
                    e.printStackTrace();
                }
            }
        });
    }
}
}

仅显示文本,但没有显示图像,并且它不起作用..

请帮助,它有什么问题,因为没有产生错误。

1 个答案:

答案 0 :(得分:0)

除了您使用==来比较字符串......

之外

将其移至onCreate

adapter = new ArrayAdapter<>(MenuActivity.this, R.layout.activity_menu, mylist);
listview.setAdapter(adapter);

在循环内部,只需执行

adapter.add(name);