我想添加一些项目ListView - 他们没有显示。ListView不显示任何添加项目
我意识到这个问题已被多次询问,但我试着按照我在那里找到的任何建议 - 没有为我工作。
这里是公共类MyListActivity我的onCreate方法的内容延伸AppCompatActivity - >
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_list);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
if (getSupportActionBar() != null) {
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
}
((EditText) findViewById(R.id.editText2)).setInputType(InputType.TYPE_NULL);
ListView view = (ListView) findViewById(R.id.myList);
adapter = new ArrayAdapter<>(this, android.R.layout.simple_list_item_1);
view.setAdapter(adapter);
adapter.add("aaaaa");
adapter.add("bbbbb");
adapter.notifyDataSetChanged();
这是我的相关布局XML - >
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.kuba.myapplication3.MyListActivity">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay"
>
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="@style/AppTheme.PopupOverlay" />
</android.support.design.widget.AppBarLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/background_dark"
android:orientation="vertical"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<EditText
android:id="@+id/editText2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textPersonName"
android:text="@string/txt_searching"
android:textColor="@android:color/white" />
<Button
android:id="@+id/button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="ButtonTxt" />
</LinearLayout>
<ListView
android:id="@+id/myList"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:dividerHeight="1dp" />
</LinearLayout>
好吧,就像我说的,“aaaa”和“bbbb”不要在任何地方展示。
在此先感谢您的任何建议!
你能显示你的适配器声明吗? – tahsinRupam
@tahsinRupam它在MyListActivity类中作为私有ArrayAdapter适配器; –
awa993
请检查我的回答请 – tahsinRupam