【发布时间】:2018-12-16 04:03:09
【问题描述】:
android 微调器默认为空或在选中项目时为空。我尝试使用微调器的默认布局,但仍然是空的。我检查了这个网站上的所有问题,但没有任何帮助。
代码如下:
activity_main.xml 上的微调视图:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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_height="match_parent"
android:layout_width="match_parent"
android:background="@color/background"
android:orientation="vertical">
<TextView
android:id="@+id/showTitle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Title"
android:textSize="20sp"
android:textAlignment="center"
android:textColor="@color/textColor"
android:fontFamily="monospace"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
/>
<Spinner
android:id="@+id/spinner"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:spinnerMode="dropdown"
>
</Spinner>
</LinearLayout>
活动:
public class ShowActivity extends AppCompatActivity {
private List<String> list;
Spinner dropdown;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_show);
TextView titleView = findViewById(R.id.showTitle);
String title = getIntent().getExtras().getString("title");
titleView.setText(title);
list = new ArrayList<>();
dropdown = findViewById(R.id.spinner);
FirebaseFirestore.getInstance().collection(title).get().addOnCompleteListener(new OnCompleteListener<QuerySnapshot>() {
@Override
public void onComplete(@NonNull Task<QuerySnapshot> task) {
if (task.isSuccessful()) {
for (QueryDocumentSnapshot document : task.getResult()) {
list.add(document.getId());
}
Log.d("Success ", list.toString());
} else {
Log.d("Failed ", "Error getting documents: ", task.getException());
}
}
});
ArrayAdapter<String> adapter = new ArrayAdapter<String>(ShowActivity.this, R.layout.spinner_items, list);
adapter.setDropDownViewResource(R.layout.spinner_items);
dropdown.setAdapter(adapter);
adapter.notifyDataSetChanged();
}
}
spinner_items.xml:
<?xml version="1.0" encoding="utf-8"?>
<TextView
android:id="@+id/spinnerTV"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@color/colorPrimary"
android:textSize="20sp"
android:text="Text"
android:gravity="start"
android:padding="10dp"
android:textColor="@color/textColor"
android:layout_marginBottom="3dp"
android:layout_margin="8dp"
/>
提前谢谢你。 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
【问题讨论】:
-
android:layout_width="match_parent"和android:layout_height="match_parent"应该是wrap_content -
这会改变下拉列表中文本视图的宽度,但选择时文本仍然不出现。
-
你也改变了高度吗?我必须查看更多您的代码才能提供帮助
-
@Emmanuel 我已经更新了这个问题现在有帮助吗?