Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/208.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 将项目添加到数据源不会';不显示在列表视图中_Android_Listview_Arraylist_Listadapter - Fatal编程技术网

Android 将项目添加到数据源不会';不显示在列表视图中

Android 将项目添加到数据源不会';不显示在列表视图中,android,listview,arraylist,listadapter,Android,Listview,Arraylist,Listadapter,我正在向我的数据源添加项目,并希望它显示在我的ListView中。出于某种原因,什么也没有出现: 适配器: private class STCompanyAdapter extends ArrayAdapter<STCompany> { private ArrayList<STCompany> items; public STCompanyAdapter(Context context, int textViewResourceId,

我正在向我的数据源添加项目,并希望它显示在我的ListView中。出于某种原因,什么也没有出现:

适配器:

private class STCompanyAdapter extends ArrayAdapter<STCompany> {

        private ArrayList<STCompany> items;

        public STCompanyAdapter(Context context, int textViewResourceId,
                ArrayList<STCompany> items) {
            super(context, textViewResourceId, items);
            this.items = items;
        }

        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            View v = convertView;
            if (v == null) {
                LayoutInflater vi = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
                v = vi.inflate(R.layout.addstocksrow, null);
            }
            STCompany q = items.get(position);
            if (q != null) {
                TextView symbolText = (TextView) v.findViewById(R.id.toptext);
                TextView nameText = (TextView) v.findViewById(R.id.bottomtext);

                if (nameText != null) {
                    nameText.setText(q.getSymbol());
                }
                if (symbolText != null) {
                    symbolText.setText(q.getName());
                }
            }
            return v;
        }
    }
以下是我的布局:

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout android:layout_width="fill_parent" android:layout_height="fill_parent" xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/LinearLayout">
<EditText android:id="@+id/addStocksEditText" android:text="Search company or stock" android:layout_width="200dp" android:layout_height="50dp"></EditText><Button android:layout_height="wrap_content" android:text="Search" android:id="@+id/searchButton" android:layout_width="fill_parent"></Button><ListView android:id="@+id/symbolsListView" android:layout_width="fill_parent" android:layout_height="fill_parent"></ListView>


</LinearLayout>

尝试companies.add(myCompany)而不是companiesAdapter.add(myCompany)。

尝试companies.add(myCompany)而不是companiesAdapter.add(myCompany)。

问题是我的布局。listview没有出现。代码正常。

问题是我的布局。listview没有出现。代码没问题

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout android:layout_width="fill_parent" android:layout_height="fill_parent" xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/LinearLayout">
<EditText android:id="@+id/addStocksEditText" android:text="Search company or stock" android:layout_width="200dp" android:layout_height="50dp"></EditText><Button android:layout_height="wrap_content" android:text="Search" android:id="@+id/searchButton" android:layout_width="fill_parent"></Button><ListView android:id="@+id/symbolsListView" android:layout_width="fill_parent" android:layout_height="fill_parent"></ListView>


</LinearLayout>