亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何將 PLEASE SELECT 錯誤添加到 JSON Spinner

如何將 PLEASE SELECT 錯誤添加到 JSON Spinner

繁星點點滴滴 2023-06-14 16:12:59
我有一個應用程序,您可以在其中將圖像上傳到我公司的服務器我有 2 個微調器填充了 json 數據,微調器中的選定項目被傳遞給上傳 url 的 uri.builder,我已經看到很多關于設置請選擇微調器上的選項但是我的微調器的請選擇選項作為項目編碼到我的 JSON 數據中?,F在我想要的是,如果選擇了 please select item 以提示用戶在微調器中選擇一個項目,應用程序將給出一個錯誤總而言之,我的微調器中填充了 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;@Overrideprotected 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")
查看完整描述

2 回答

?
冉冉說

TA貢獻1877條經驗 獲得超1個贊

將以下行添加到微調器方法的頂部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;


    }


查看完整回答
反對 回復 2023-06-14
?
DIEA

TA貢獻1820條經驗 獲得超2個贊

在第一個位置添加您的項目。在 Spinner 上添加一個 Item Selected Check Listner 并添加一個檢查是否選擇的值是第一個。如果先顯示消息


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

    }


});


查看完整回答
反對 回復 2023-06-14
  • 2 回答
  • 0 關注
  • 156 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號