我有一个应用程序,你可以上传图像到我的公司服务器我有2个纺纱机填充json数据,纺纱机中的选定项目被传递到uri.builder上传网址,我在SO上看到了很多关于在纺纱机上设置请选择选项的问题,但是我纺纱机的请选择选项作为一个项目被编码到我的JSON数据中。现在我想要的是,如果请选择项目被选中,应用程序会给出一个错误,以提示用户在纺纱机中选择一个项目
总结一下,我的微调器中填充了json数据,json数据中的第一项是“请选择”。现在,如果选择了“请选择”选项,我希望出现一条错误消息。
public class SecondActivity extends AppCompatActivity implements
View.OnClickListener {
private final int PICK_IMAGE=12345;
private final int REQUEST_CAMERA=6352;
private static final int REQUEST_CAMERA_ACCESS_PERMISSION=5674;
private Bitmap bitmap;
private ImageView imageView;
String myURL;
Spinner spinner;
Spinner spinner2;
String URL;
String URL2;
ArrayList<String> CategoryName;
ArrayList<String> ClientName;
String Item;
String Item2;
String email;
String clientId;
String pwd;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_second);
imageView=findViewById(R.id.imageView);
Button fromCamera=findViewById(R.id.fromCamera);
Button fromGallery=findViewById(R.id.fromGallery);
Button upload=findViewById(R.id.upload);
CategoryName=new ArrayList<>();
ClientName=new ArrayList<>();
spinner=findViewById(R.id.spinner);
spinner2=findViewById(R.id.spinner2);
email = getSharedPreferences("MyPrefs", MODE_PRIVATE).getString("name", "");
clientId= getSharedPreferences("MyPrefs", MODE_PRIVATE).getString("id", "");
pwd= getSharedPreferences("MyPrefs", MODE_PRIVATE).getString("password", "");
CheckBox chk =findViewById(R.id.chk1);
if (chk.isChecked()) {
Uri.Builder builder=new Uri.Builder();
builder.scheme("https")
.authority("www.smartpractice.co.za")
.appendPath("files-upload-phone-app.asp")
.appendQueryParameter("MyForm", "Yes")
.appendQueryParameter("ClientID", clientId)
.appendQueryParameter("Username", email)
.appendQueryParameter("Pwd", pwd)
.appendQueryParameter("Category", Item)
.appendQueryParameter("ClientName", Item2)
.appendQueryParameter("NoEmail", "Yes");
myURL=builder.build().toString();
} else {
Uri.Builder builder=new Uri.Builder();
builder.scheme("https")
.authority("www.smartpractice.co.za")
.appendPath("files-upload-phone-app.asp")
.appendQueryParameter("MyForm", "Yes")
.appendQueryParameter("ClientID", clientId)
.appendQueryParameter("Username", email)
.appendQueryParameter("Pwd", pwd)
.appendQueryParameter("Category", Item)
.appendQueryParameter("ClientName", Item2)
.appendQueryParameter("NoEmail", "Yes");
myURL=builder.build().toString();
}
upload.setOnClickListener(this);
fromCamera.setOnClickListener(this);
fromGallery.setOnClickListener(this);
Uri.Builder builder=new Uri.Builder();
builder.scheme("https")
.authority("www.smartpractice.co.za")
.appendPath("app-categories.asp")
.appendQueryParameter("MyForm", "Yes")
.appendQueryParameter("ClientID",clientId )
.appendQueryParameter("Username",email )
.appendQueryParameter("Pwd",pwd );
URL=builder.build().toString();
Uri.Builder builder2=new Uri.Builder();
builder2.scheme("https")
.authority("www.smartpractice.co.za")
.appendPath("app-clients.asp")
.appendQueryParameter("MyForm", "Yes")
.appendQueryParameter("ClientID",clientId )
.appendQueryParameter("Username",email )
.appendQueryParameter("Pwd",pwd );
URL2=builder2.build().toString();
loadSpinnerData(URL);
loadSpinnerData2(URL2);
项目选择代码上的微调器1
spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener()
{
@Override
public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {
String country=spinner.getItemAtPosition(spinner.getSelectedItemPosition()).toString();
Toast.makeText(getApplicationContext(), country, Toast.LENGTH_LONG).show();
Item=spinner.getSelectedItem().toString();
spinner.getSelectedItemPosition();
}
@Override
public void onNothingSelected(AdapterView<?> adapterView) {
}
});
旋转器2关于itme选择代码
spinner2.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {
String country=spinner2.getItemAtPosition(spinner2.getSelectedItemPosition()).toString();
Toast.makeText(getApplicationContext(), country, Toast.LENGTH_LONG).show();
Item2=spinner2.getSelectedItem().toString();
}
@Override
public void onNothingSelected(AdapterView<?> adapterView) {
}
}
}
spinner 1用于从服务器加载JSON数据的代码
private void loadSpinnerData(String url) {
RequestQueue requestQueue=Volley.newRequestQueue(getApplicationContext());
StringRequest stringRequest=new StringRequest(Request.Method.GET, url, new Response.Listener<String>() {
@Override
public void onResponse(String response) {
try {
JSONObject jsonObject=new JSONObject(response);
if (jsonObject.getInt("success") == 1) {
JSONArray jsonArray=jsonObject.getJSONArray("Name");
for (int i=0; i < jsonArray.length(); i++) {
JSONObject jsonObject1=jsonArray.getJSONObject(i);
String country=jsonObject1.getString("Category");
CategoryName.add(country);
}
}
spinner.setAdapter(new ArrayAdapter<>(SecondActivity.this, android.R.layout.simple_spinner_dropdown_item, CategoryName));
} catch (JSONException e) {
e.printStackTrace();
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
error.printStackTrace();
}
});
int socketTimeout=30000;
RetryPolicy policy=new DefaultRetryPolicy(socketTimeout, DefaultRetryPolicy.DEFAULT_MAX_RETRIES, DefaultRetryPolicy.DEFAULT_BACKOFF_MULT);
stringRequest.setRetryPolicy(policy);
requestQueue.add(stringRequest);
}
spinner 2从服务器加载JSON数据的代码
private void loadSpinnerData2(String url) {
RequestQueue requestQueue=Volley.newRequestQueue(getApplicationContext());
StringRequest stringRequest=new StringRequest(Request.Method.GET, url, new Response.Listener<String>() {
@Override
public void onResponse(String response) {
try {
JSONObject jsonObject=new JSONObject(response);
if (jsonObject.getInt("success") == 1) {
JSONArray jsonArray=jsonObject.getJSONArray("Name");
for (int i=0; i < jsonArray.length(); i++) {
JSONObject jsonObject1=jsonArray.getJSONObject(i);
String clientName=jsonObject1.getString("ClientName");
ClientName.add(clientName);
}
}
spinner2.setAdapter(new ArrayAdapter<>(SecondActivity.this, android.R.layout.simple_spinner_dropdown_item, ClientName));
} catch (JSONException e) {
e.printStackTrace();
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
error.printStackTrace();
}
});
int socketTimeout=30000;
RetryPolicy policy=new DefaultRetryPolicy(socketTimeout, DefaultRetryPolicy.DEFAULT_MAX_RETRIES, DefaultRetryPolicy.DEFAULT_BACKOFF_MULT);
stringRequest.setRetryPolicy(policy);
requestQueue.add(stringRequest);
}
在第一个位置添加您的项目。在旋转器上添加一个项目选择检查列表,如果选择的值是第一个,则添加一个检查。如果是第一个,则显示一条消息
spinner.setOnItemSelectedListener(new OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parentView, View selectedItemView, int position, long id) {
// your code here
if(position==0)
Toast.makeText(getContext,"Please select a value",Toast.LENGTH_LONG).show()
}
@Override
public void onNothingSelected(AdapterView<?> parentView) {
// your code here
}
});
将以下行添加到微调器的onItemSelected
方法的顶部。
if(i==0){
///Here you need to show the error msg for the first item selected
Log.v("ERROR","Please select an item callded");
//return is used the break the flow of the app so the code below does not run in this case
return;
}
在这里json 如何使用库boost获得更新的值4? 我知道怎么取这样一个“ts”值。但是我不明白如何取两个括号的值
本节的 TypeScript 版本有待更新 若要添加列以选择单行或所有行,可以使用 GridRowSelectionMixin。 GridRowSelectionMixin 在 Serenity 1.6.8+ 有效。 示例代码: public class MyGrid : EntityGrid<MyRow> { private GridRowSelectionMixin rowSelect
我正在使用选择一个菜单从
当listview开始时,我发现第一个按钮被选中了?我试着用listview做点击按钮事件,但我不知道原因!我如何使它像列表中的所有按钮一样默认?请看一下图片。
问题内容: 使用核心jQuery,如何删除选择框的所有选项,然后添加一个选项并选择它? 我的选择框如下。 编辑:以下代码有助于链接。但是,(在Internet Explorer中)未选择添加的选项。(我确实在和中都使用了相同的“值” 。) 编辑:试图使其模仿此代码,每当重置页面/窗体时,我都使用以下代码。该选择框由一组单选按钮填充。距离更近,但是未像使用时那样显示选择的选项。我现有的代码没什么错-