创建活动时设置微调器标题

时间:2017-06-05 09:43:16

标签: android

我有一个微调器,其元素由arrayList.this arraylist设置,通过调用api获取数据。我已将标题设置在arrayList的第0位。问题是我想在创建活动时显示此标题。但这只会在api调用成功时设置。这需要一些时间来加载数据。任何人都可以给我更好的想法设置旋转器的标题。

3 个答案:

答案 0 :(得分:0)

如果数据来自api,那么你可以在屏幕上添加对话框并隐藏标题直到api调用成功..当你得到响应时,然后显示titleview并从api添加标题。并且api响应为false然后显示错误..因此用户将获得更好的视图..

由于

答案 1 :(得分:0)

这样做

 ArrayAdapter stringArrayAdapter = new ArrayAdapter(this, 
 R.layout.spinner_item, CatagoryName);

    // create a spinner
    Spinner spinner = (Spinner) findViewById(R.id.spinner);
    // add adapter to spinner
    spinner.setAdapter(stringArrayAdapter);
    // create listener and add to spinner
    spinner.setOnItemSelectedListener(new 
     AdapterView.OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int 
       position, long id) {
              // put code which recognize a selected element
        }

答案 2 :(得分:0)

  

试试这种方式

ArrayList<String> list  = new ArrayList<>();
        list.add(0,"Please Select");

        ArrayAdapter stringArrayAdapter = new ArrayAdapter(this,  android.R.layout.simple_spinner_item, CatagoryName); 
        Spinner spinner = (Spinner) findViewById(R.id.spinner);
        spinner.setAdapter(stringArrayAdapter);

        // now call the API for data 

        //After data received, you have to make  temp list to store response
        ArrayList<String> Templist  = new ArrayList<>();

        //Templist = Server response

        //now add templist in main List
        list.addAll(Templist);
        // and call this
        stringArrayAdapter.notifyDataSetChanged();