我一直围着这个圈子走.如果它与数据库中的记录匹配,我已设法将微调器设置为显示列表中的项目,但现在在保存记录时从微调器获取所选项目时出现问题.我改为像'android.database.sqlite.SQLiteCursor@44fa41b0'.
在我的saveInspection()方法中,我使用的是inspectedBySpinner.getSelectedItem().toString(); (正如在这篇文章的第二个回答中详细说明你如何获得Spinner的选定值?)没有成功..(如此接近但没有香蕉!).
我确信这是显而易见的事情,但非常感谢:
public class InspectionEdit extends Activity {
final Context context = this;
private EditText inspectionReferenceEditText;
private EditText inspectionCompanyEditText;
private Button inspectionDateButton;
private Spinner inspectedBySpinner;
private Button saveButton;
private Button cancelButton;
protected boolean changesMade;
private AlertDialog unsavedChangesDialog;
private Button addInspectorButton;
private int mYear;
private int mMonth;
private int mDay;
private StringBuilder mToday;
private RMDbAdapter rmDbHelper;
private long inspectionId;
private String inspectedBySpinnerData;
//private String inspectors;
static final int DATE_DIALOG_ID = 0;
@Override
protected void onCreate(Bundle savedInstanceState) { …Run Code Online (Sandbox Code Playgroud) 我不知道为什么onItemSelected在活动开始时触发它自己?是因为我从一开始就有关于微调器的首字母数据?
我有两个微调器,当我选择第一个微调器时,根据第一个微调器选择,选择第二个微调器阵列来进行更改。
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string-array name="type">
<item>Select Type</item>
<item >Color</item>
<item >Weeks</item>
</string-array>
<string-array name="color">
<item>Blue</item>
<item >Orange</item>
<item >Red</item>
<item >Green</item>
</string-array>
<string-array name="weeks">
<item>Sunday</item>
<item >Monday</item>
<item >Tuesday</item>
<item >Wednesday</item>
</string-array>
</resources>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Select Type:"/>
<Spinner
android:id="@+id/spinner"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:prompt="@string/spinner_title"
android:drawSelectorOnTop = "true"/>
<Spinner
android:id="@+id/spinner1"
android:layout_width="match_parent"
android:prompt="@string/spinner_title1"
android:layout_height="wrap_content" />
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(
this, R.array.type, android.R.layout.simple_spinner_item);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner.setAdapter(adapter);
Run Code Online (Sandbox Code Playgroud)
在这两个微调器中,在第一个微调器中,我使用了“类型”,根据第一个微调器的类型选择,如何更改第二个微调器以使用阵列颜色和周数?
提前致谢
android android-intent android-layout android-listview android-spinner
我使用json中的适配器数据创建微调器.但是为什么微调器没有显示文本而在选择值时不显示.有人可以帮帮我.
微调
<Spinner android:id="@+id/spinCity"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:padding="15dp"
android:textColor = "#000000"
android:prompt="@string/city_prompt"
/>
Run Code Online (Sandbox Code Playgroud)
为旋转器加载json.
cityItems = new ArrayList<City>();
cityNames = new ArrayList<String>();
JsonObjectRequest jsonReq = new JsonObjectRequest(
AppConfig.URL_CITY, null, new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
VolleyLog.d(TAG, "Response: " + response.toString());
if (response != null) {
try {
JSONArray feedArray = response.getJSONArray("result");
for (int i = 0; i < feedArray.length(); i++) {
JSONObject feedObj = (JSONObject) feedArray.get(i);
City item = new City();
item.setId(feedObj.getInt("id"));
item.setCity(feedObj.getString("city"));
cityItems.add(item);
cityNames.add(feedObj.getString("city"));
}
} …Run Code Online (Sandbox Code Playgroud) 数据库中 Spinner 的值。我很困惑为 Spinner 添加提示,我关注了 SO 中的一些帖子,但我对这个地方感到震惊,我尝试了这个
Spinner sp = (Spinner)findViewById(R.id.spinner);
sp.setSelection(pos);
Run Code Online (Sandbox Code Playgroud)
位置有整数值,所以我把它作为位置的整数值,我也尝试在 setSeletction() 方法中使用 getCount()
主程序
//spinner for customer
sp=(Spinner)findViewById(R.id.spinner);
adapter=new ArrayAdapter<String>(this,R.layout.spinner_layout,R.id.txt,listItems);
sp.setAdapter(adapter);
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.sales_order);
cus_name = (Spinner) findViewById(R.id.spinner);//customer spinner
// Permission StrictMode
if (android.os.Build.VERSION.SDK_INT > 9) {
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);
}
//spinner for customer
sp=(Spinner)findViewById(R.id.spinner);
adapter=new ArrayAdapter<String>(this,R.layout.spinner_layout,R.id.txt,listItems);
sp.setAdapter(adapter);
}
private class BackTask extends AsyncTask<Void,Void,Void> {
ArrayList<String> list;
protected void onPreExecute(){
super.onPreExecute();
list=new ArrayList<>();
}
protected Void doInBackground(Void...params){
InputStream is=null;
String …Run Code Online (Sandbox Code Playgroud) 首先请检查此图片:
它显示了一个美丽而漂亮的Spinner,我的Spinner看起来像这样:
这是我的所有源代码.
活动xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="amaz1ngc0de.com.br.spinnertest.MainActivity">
<Spinner
android:id="@+id/sp_paymentType"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
>
</Spinner>
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)
我的问题是:如何实现教程中显示的相同布局?
PS:我已经检查了这个主题:正确使用Spinner,遵循材料设计指南,它说的是关于主题的东西,但是我不能使它工作,我正在遵循的教程就是那个:Spinners
我Spinner在spinnerMode下拉列表中使用带有自定义适配器和自定义视图的小部件。我的问题是我无法删除投射Spinner.

这是里面的代码 Activity
mSpinner = (Spinner)findViewById(R.id.spinner);
setSpinnerData();
customSpinnerAdapter = new CustomSpinnerAdapter(this,R.layout.spinner_item,CustomListViewValuesArr );
mSpinner.setAdapter(customSpinnerAdapter);
mSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) {
itemSelect(pos);
}
@Override
public void onNothingSelected(AdapterView<?> adapterView) {
}
});
Run Code Online (Sandbox Code Playgroud)
另外这里面的微调Layout的Activity:
<Spinner
android:id="@+id/spinner"
android:layout_centerInParent="true"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:spinnerMode="dropdown"
android:background="@null"
android:padding="0dp"
android:layout_margin="15dp"
android:dropDownVerticalOffset="@dimen/vertical_offset"/>
Run Code Online (Sandbox Code Playgroud)
我使用我自己的自定义Adapter:
public class CustomSpinnerAdapter extends ArrayAdapter {
public ArrayList CustomListViewValuesArr;
LayoutInflater inflater;
Typeface myTypeFace;
SpinnerItem item = null;
public …Run Code Online (Sandbox Code Playgroud) 我有一个表示表单的活动布局.表单包含一些表单字段,包括Spinner.
布局类型为ConstraintLayout.
因为Spinner控件没有基线,所以我无法正确地垂直对齐我的"Kind"标签.我在顶部使用24 dp作为临时值.解决方案,但因为Spinner的高度增加,我不喜欢这个解决方案.
是否有更好的解决方案让Kind标签正确对齐?
您好,我使用我的 Android 设备,我有两个微调器,并使用改造来填充我的微调器。我设法填充第一个旋转器。但我不知道如何让我的第二个微调器填充在从第一个微调器中选择的 id 下。我正在使用 codeigniter 休息控制器来传递 id 并希望使用第二个微调器的改造来检索它,但我不知道该怎么做?请帮我。
我已经通过传递 id 创建了 Rest Controller。已经创建了 ApiInterface。和 beans 来获取详细数据。第一个旋转器工作良好。
宣言
classSpinner = (Spinner) findViewById(R.id.classSpinner);
divSpinner = (Spinner) findViewById(R.id.divSpinner);
classSpinner.setAdapter(mAdapter);
mApiInterface = ApiClient.getClient().create(ApiInterface.class);
getAllProvinsi();
Run Code Online (Sandbox Code Playgroud)
API接口
public interface ApiInterface {
//first spinner
@GET("Testpage/provinsi")
Call<GetProvinsi> getProvinsi();
//second spinner that I needed how to pass the id? and get data by id selected from first spinner
@GET("Testpage/kotabyprovid/provinsi_id/")
Call<GetKota> getKota();
}
Run Code Online (Sandbox Code Playgroud)
GetProvinsi(第一个旋转器)
public class GetProvinsi {
@SerializedName("result")
List<Provinsi> listDataProvinsi;
public List<Provinsi> getListDataProvinsi() {
return listDataProvinsi;
}
public …Run Code Online (Sandbox Code Playgroud) 我正在使用 Material 在 android studio 中使用 Java 设计一个带有下拉列表的表单。
我想将用户从下拉列表中所做的选择保存到一个字符串中,这样我就可以将其保存到 Firebase,但是当我尝试记录结果时,它说选择为空。
有谁知道我如何捕获用户从这种类型的下拉菜单中选择的内容?我以前确实有一个可以工作的 Spinner,但这似乎并没有以相同的方式工作。
我的XML代码如下
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/cpdTypeLayout"
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox.ExposedDropdownMenu"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginEnd="16dp"
android:hint="Activity Type">
<AutoCompleteTextView
android:id="@+id/cpdType"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="none" />
</com.google.android.material.textfield.TextInputLayout>
Run Code Online (Sandbox Code Playgroud)
我的 AddAdactivity.java 代码是
//CPD TYPE DROPDOWN MENU
cpdTypeLayout = findViewById(R.id.cpdTypeLayout);
cpdType = findViewById(R.id.cpdType);
String[] type = new String[]{
"Formal Education Completed", "Other Completed", "Professional Activities", "Self-Directed Learning", "Work-Based Learning"
};
ArrayAdapter<String> adapterType = new ArrayAdapter<>(
AddActivity.this,
R.layout.dropdown_item,
type
);
cpdType.setAdapter(adapterType);
cpdType.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int …Run Code Online (Sandbox Code Playgroud) java android android-spinner android-textinputlayout material-components-android
android ×10
android-spinner ×10
java ×3
json ×1
material-components-android ×1
retrofit ×1
spinner ×1