0

我在堆栈上找到了为进度圈添加这些行:

requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);  
setProgressBarIndeterminateVisibility(true);
setProgressBarIndeterminateVisibility(false);

我有一个带有搜索小部件的操作栏,一旦它从 api 获取 json 并对其进行解析,它就会执行搜索并在列表视图中显示结果。

当我像这样将上面的代码添加到我的搜索代码中时,它永远不会返回结果,我根本看不到微调器:

try {

                //start progress bar
                requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);  
                setProgressBarIndeterminateVisibility(true);

                System.out.println(result);
                Log.d("asycTask", "[ Gets into asyc task ]");
                ///get 
                Log.d("search", "[ check if we get search results ]");
                Log.d("search", "[" + result + "]");

                JSONObject json = new JSONObject(result);

                //acces listview
                lv = (ListView) findViewById(android.R.id.list);

                //make array list for beer
                final List<BeerData> beerList = new ArrayList<BeerData>();



                //get json items
                for(int i = 0; i < json.getJSONArray("data").length(); i++) {

                    String beerId = GetBeerDataFromJSON(i,"id", json);
                    String beerName = GetBeerDataFromJSON(i,"name", json);
                    String beerDescription = GetBeerDataFromJSON(i,"description" , json);
                    String beerAbv = GetBeerDataFromJSON(i,"abv" , json);
                    String beerIbu = GetBeerDataFromJSON(i,"ibu" , json);
                    String beerIcon = GetBeerIconsFromJSON(i, "icon",json );
                    String beerMediumIcon = GetBeerIconsFromJSON(i, "medium",json );
                    String beerLargeIcon = GetBeerIconsFromJSON(i, "large",json );
                    String beerGlass = GetBeerGlassFromJSON(i, json );
                    String beerStyle = GetBeerStyleFromJSON(i,"name", json );
                    String beerStyleDescription = GetBeerStyleFromJSON(i,"description", json );
                    String beerBreweryId = GetBeerBreweryInfoFromJSON(i, "id", json );
                    String beerBreweryName = GetBeerBreweryInfoFromJSON(i, "name", json );
                    String beerBreweryDescription = GetBeerBreweryInfoFromJSON(i, "description", json );
                    String beerBreweryWebsite = GetBeerBreweryInfoFromJSON(i, "website", json );
                    String beerBreweryYear = GetBeerBreweryInfoFromJSON(i, "established", json );
                    String beerBreweryIcon = GetBeerBreweryIconsFromJSON(i,"large",json);



                    //create beer object
                    BeerData thisBeer = new BeerData(beerName, beerId, beerDescription, beerAbv, beerIbu, beerIcon,
                            beerMediumIcon,beerLargeIcon, beerGlass, beerStyle, beerStyleDescription, beerBreweryId, beerBreweryName,
                            beerBreweryDescription, beerBreweryYear, beerBreweryWebsite,beerBreweryIcon);

                    //add beer to list
                    beerList.add(thisBeer);


                }

                //update listview
                ArrayAdapter<BeerData> adapter1 = new ArrayAdapter<BeerData>(MainActivity.this, R.layout.list_item, R.id.itemName, beerList);
                lv.setAdapter(adapter1);

                //set up clicks
                lv.setOnItemClickListener(new OnItemClickListener() {    
                       @Override
                       public void onItemClick(AdapterView<?> arg0, View arg1,
                                                int arg2, long arg3) {
                              Intent i = new Intent(MainActivity.this, BeerPage.class); 

                              BeerData beerInfo = beerList.get(arg2);


                              //Toast.makeText(MainActivity.this,  beerInfo.beerName, Toast.LENGTH_SHORT).show();

                              i.putExtra("myBeerObject",  beerInfo);   
                              i.setClass(MainActivity.this, BeerPage.class);


                              startActivity(i); 



                       } 
                   });

                //end progress bar
                setProgressBarIndeterminateVisibility(false);






            } catch (Exception e) {
                Log.d("ReadBeerDataTask", e.getLocalizedMessage());
            }          
        }
    } 

列表视图的 xml 是:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical"
    tools:context=".MainActivity" >

    <LinearLayout
        android:id="@+id/linlaHeaderProgress"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:gravity="center"
        android:orientation="vertical"
        android:visibility="gone" >

        <ProgressBar
            android:id="@+id/pbHeaderProgress"
            style="android@style/Spinner"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" >
        </ProgressBar>
    </LinearLayout>

    <ListView
        android:id="@android:id/list"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:dividerHeight="0.1dp"
        >
    </ListView>

</LinearLayout>
4

0 回答 0