Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/218.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
无法在android中滚动列表视图_Android - Fatal编程技术网

无法在android中滚动列表视图

无法在android中滚动列表视图,android,Android,我有一个问题,我通过代码在LinearLayout中动态添加listview,并将EndlesAdapter设置为,数据显示正确,但无法在列表中从上到下滚动。我不知道为什么?请向我建议任何解决方案 代码: public void setValuesInCategoryChild(String url, final String filter, final String from, final String to) { if (isOnline()) {

我有一个问题,我通过代码在LinearLayout中动态添加listview,并将EndlesAdapter设置为,数据显示正确,但无法在列表中从上到下滚动。我不知道为什么?请向我建议任何解决方案

代码:

public void setValuesInCategoryChild(String url, final String filter,
            final String from, final String to) {
        if (isOnline()) {
            final ProgressDialog dialog = ProgressDialog.show(
                    ResearchList.this, "Research List       ",
                    "Please wait...   ", true);

            final Handler handler = new Handler() {

                public void handleMessage(Message msg) {

                    // System.out.println("The id after Save:"+id.get(0).toString());

                    // catagory.addAll(keyword_vector1);
                    linear_Category_Child.setVisibility(View.GONE);
                    linear_Category_Child_Child.setVisibility(View.VISIBLE);
                    // tv_Child_Header.setText("Volvo");
                    tv_CategoryChildHeader.setText(from);
                    setHeaderImage(tv_CategoryChildHeader.getText().toString());
                    System.out.println("The size of Cat Display names:"
                            + coll.getDisplayNames().size());
                    System.out.println("The size of Cat Images:"
                            + coll.getImages().size());
                    System.out.println("The size of Cat price:"
                            + coll.getPrice().size());
                    System.out.println("The size of Cat Year:"
                            + coll.getYears().size());
                    System.out.println("The size of Cat Rating:"
                            + coll.getRating().size());
                    System.out.println("The size of Cat Mpg:"
                            + coll.getMpg().size());
                    setHeaderImage(tv_CategoryChildHeader.getText().toString());
                    if(coll.getDisplayNames().size()!=0)
                    {
                        lvCategory = new ListView(ResearchList.this);
                        LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
                                LayoutParams.FILL_PARENT,
                                LayoutParams.FILL_PARENT);

                        lvCategory.setLayoutParams(params);

                    // Adapter for MPG Search
                    demoAdapterCat = new DemoAdapterCat();
                    lvCategory.setAdapter(demoAdapterCat);
                    layout_ResearchList_BrandList.addView(lvCategory);
                    Utility.setListViewHeightBasedOnChildren(lvCategory);
                    }
                    else
                    {
                        /*lvCategory.invalidate();
                        lvCategory.setAdapter(null);*/
                        AlertDialog.Builder builder = new Builder(ResearchList.this);
                        builder.setTitle("Attention!");
                        builder.setMessage("No Data Available for the Particular Search.");
                        builder.setPositiveButton("OK",
                                new DialogInterface.OnClickListener() {

                                    @Override
                                    public void onClick(DialogInterface dialog, int which) {
                                        // TODO Auto-generated method stub

                                    }
                                });

                        builder.create().show();
                    }
                    /*Utility util = new Utility();
                    util.setListViewHeightBasedOnChildren(lvCategory);*/
                    dialog.dismiss();
                }
            };

            final Thread checkUpdate = new Thread() {

                public void run() {
                    try {
                        String sortEncode = URLEncoder.encode("mpg");
                        String filterEncode = URLEncoder.encode(filter);
                        String clientEncode = URLEncoder.encode("10030812");
                        String fromEncode = URLEncoder.encode(from);
                        String toEncode = URLEncoder.encode(to);
                        String catUrl = "/v1/vehicles/get-make-models.json?sort="
                                + sortEncode
                                + "&filter="
                                + filterEncode
                                + "&client-id="
                                + clientEncode
                                + "&from="
                                + fromEncode;
                        genSig = new GetSignature(catUrl, "acura");
                        try {
                            signature = genSig.getUrlFromString();
                        } catch (InvalidKeyException e1) {
                            // TODO Auto-generated catch block
                            e1.printStackTrace();
                        } catch (NoSuchAlgorithmException e1) {
                            // TODO Auto-generated catch block
                            e1.printStackTrace();
                        }
                        // jsonString =
                        // getJsonSring("http://api.highgearmedia.com/v1/vehicles/get-models.json?make=acura&client-id=10030812&signature=LWQbdAlJVxlXZ1VO2mfqAA==");
                        // String signatureEncode =
                        // URLEncoder.encode(signature);
                        String urlEncode = URLEncoder.encode(catUrl
                                + "&signature=" + signature);
                        jsonString = getJsonSring("http://apibeta.highgearmedia.com"
                                + catUrl + "&signature=" + signature);
                        System.out.println("The json category:===>"
                                + jsonString);
                    } catch (ClientProtocolException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    } catch (URISyntaxException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    } catch (IOException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }
                    JsonParse json = new JsonParse(jsonString);
                    json.parseCat();
                    LIST_SIZE = coll.getDisplayNames().size();
                    for (int i = 0; i <= BATCH_SIZE; i++) {
                        // countriesSub.add(COUNTRIES[i]);
                        countriesSubCat.add(coll.getDisplayNames().get(i));
                        imagesSubCat.add(coll.getImages().get(i));
                        YearSubCat1.add(coll.getYears().get(i));
                        YearSubCat2.add(coll.getYears().get(i + 1));
                        mpgSubCat1.add(coll.getMpg().get(i));
                        mpgSubCat2.add(coll.getMpg().get(i + 1));
                        priceSubCat1.add(coll.getPrice().get(i));
                        priceSubCat2.add(coll.getPrice().get(i + 1));
                        ratingSubCat1.add(coll.getRating().get(i));
                        ratingSubCat2.add(coll.getRating().get(i + 1));
                    }
                    setLastOffset(BATCH_SIZE);
                    handler.sendEmptyMessage(0);

                }

            };
            checkUpdate.start();
        } else {
            AlertDialog.Builder builder = new Builder(ResearchList.this);
            builder.setTitle("Attention!");
            builder.setMessage("Network Connection unavailable.");
            builder.setPositiveButton("OK",
                    new DialogInterface.OnClickListener() {

                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            // TODO Auto-generated method stub

                        }
                    });

            builder.create().show();
        }

    }
<LinearLayout
                android:id="@+id/linear_ResearchListCategoryChild_Child"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:orientation="vertical"
                android:visibility="gone" >

                <RelativeLayout
                    android:id="@+id/linear_ResearchListCategoryChild_Child_HeaderBlock"
                    android:layout_width="fill_parent"
                    android:layout_height="40dip"
                    android:background="@drawable/catagory_bar"
                    android:orientation="horizontal" >

                    <TextView
                        android:id="@+id/tv_ResearchListCategoryChild_Child_Header"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_centerVertical="true"
                        android:text="Work in Progress"
                        android:textColor="#ffffff"
                        android:textStyle="bold" android:layout_marginLeft="60dip"/>

                    <ImageView
                        android:id="@+id/img_ResearchListCategory_ChildHeader"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_alignParentLeft="true"
                        android:layout_centerVertical="true"
                        android:layout_marginLeft="10dip"
                        android:src="@drawable/up_arrow" />

                    <ImageView
                        android:id="@+id/imageView2"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_alignParentRight="true"
                        android:layout_centerVertical="true"
                        android:layout_marginRight="10dp"
                        android:src="@drawable/list_arrow_up" />

                </RelativeLayout>

                <RelativeLayout
                    android:id="@+id/linear_ResearchListCategoryChild_Child_Header"
                    android:layout_width="fill_parent"
                    android:layout_height="40dip"
                    android:background="@drawable/nav_bg"
                    android:orientation="horizontal" >

                    <TextView
                        android:id="@+id/textView5"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_alignParentLeft="true"
                        android:layout_centerVertical="true"
                        android:layout_marginLeft="5dip"
                        android:clickable="true"
                        android:text="Highest Rated"
                        android:textColor="#ffffff"
                        android:textStyle="bold" android:gravity="center"/>

                    <TextView
                        android:id="@+id/textView6"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_alignBaseline="@+id/textView5"
                        android:layout_alignBottom="@+id/textView5"
                        android:layout_marginLeft="30dp"
                        android:layout_toRightOf="@+id/textView5"
                        android:clickable="true"
                        android:text="A-Z"
                        android:textColor="#ffffff"
                        android:textStyle="bold" android:gravity="center"/>

                    <TextView
                        android:id="@+id/textView7"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_alignBaseline="@+id/textView6"
                        android:layout_alignBottom="@+id/textView6"
                        android:layout_marginLeft="40dp"
                        android:layout_toRightOf="@+id/textView6"
                        android:clickable="true"
                        android:text="Price"
                        android:textColor="#ffffff"
                        android:textStyle="bold" android:gravity="center"/>

                    <TextView
                        android:id="@+id/textView8"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_alignBaseline="@+id/textView7"
                        android:layout_alignBottom="@+id/textView7"
                        android:layout_alignParentRight="true"
                        android:layout_marginRight="14dp"
                        android:clickable="true"
                        android:text="MPG"
                        android:textColor="#ffffff"
                        android:textStyle="bold" android:gravity="center"/>
                </RelativeLayout>

                <!--
                <RelativeLayout 
                    android:id="@+id/relative_down_arrow"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:visibility="visible"
                    >

                </RelativeLayout>

                -->

                <LinearLayout
                    android:id="@+id/linearArrowLayout"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:orientation="horizontal"
                    android:visibility="visible">

                    <ImageView
                        android:id="@+id/Highly_rated"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_marginLeft="51dp"
                        android:src="@drawable/selector_arrow"
                        android:visibility="invisible" />

                    <ImageView
                        android:id="@+id/AZ_arrow"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_marginLeft="78dp"
                        android:src="@drawable/selector_arrow"
                        android:visibility="invisible" />

                    <ImageView
                        android:id="@+id/Price_arrow"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_marginLeft="59dp"
                        android:src="@drawable/selector_arrow"
                        android:visibility="invisible" />

                    <ImageView
                        android:id="@+id/MPG"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_marginLeft="55dp"
                        android:src="@drawable/selector_arrow"
                        android:visibility="invisible" />
                </LinearLayout>
                <LinearLayout 
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginLeft="12dip"
                    android:layout_marginRight="12dip" android:background="#ffffff" android:id="@+id/layout_ResearchList_BrandList">
                </LinearLayout>
            </LinearLayout>
public void setValuesInCategoryChild(字符串url,最终字符串筛选器,
最终字符串从,最终字符串到){
if(isOnline()){
最终ProgressDialog=ProgressDialog.show(
研究列表。此为“研究列表”,
“请稍等……”,对);
最终处理程序=新处理程序(){
公共无效handleMessage(消息消息消息){
//System.out.println(“保存后的id:+id.get(0.toString());
//addAll(关键字_向量1);
线性\类别\子项设置可见性(View.GONE);
线性\类别\子\子集合可见性(View.VISIBLE);
//tv_Child_Header.setText(“沃尔沃”);
tv_CategoryChildHeader.setText(from);
setHeaderImage(tv_CategoryChildHeader.getText().toString());
System.out.println(“Cat显示名称的大小:”
+coll.getDisplayNames().size());
System.out.println(“Cat图像的大小:”
+coll.getImages().size());
System.out.println(“猫价的大小:”
+coll.getPrice().size());
System.out.println(“猫年的大小:”
+coll.getYears().size());
System.out.println(“Cat额定值的大小:”
+coll.getRating().size());
System.out.println(“Cat Mpg的大小:”
+coll.getMpg().size());
setHeaderImage(tv_CategoryChildHeader.getText().toString());
如果(coll.getDisplayNames().size()!=0)
{
lvCategory=newlistview(ResearchList.this);
LinearLayout.LayoutParams params=新的LinearLayout.LayoutParams(
LayoutParams.FILL\u父级,
LayoutParams.FILL\u PARENT);
lvCategory.setLayoutParams(参数);
//MPG搜索适配器
demoAdapterCat=新的demoAdapterCat();
lvCategory.setAdapter(demoAdapterCat);
布局\研究列表\品牌列表。添加视图(lvCategory);
实用工具。setListViewHeightBasedOnChildren(lvCategory);
}
其他的
{
/*lvCategory.invalidate();
lvCategory.setAdapter(null)*/
AlertDialog.Builder=新生成器(ResearchList.this);
builder.setTitle(“注意!”);
setMessage(“没有可用于特定搜索的数据”);
builder.setPositiveButton(“确定”,
新建DialogInterface.OnClickListener(){
@凌驾
public void onClick(DialogInterface dialog,int which){
//TODO自动生成的方法存根
}
});
builder.create().show();
}
/*实用工具util=新实用工具();
util.setListViewHeightBasedOnChildren(lvCategory)*/
dialog.dismise();
}
};
最终线程检查更新=新线程(){
公开募捐{
试一试{
字符串sortEncode=urlcoder.encode(“mpg”);
字符串filterEncode=URLEncoder.encode(过滤器);
字符串clientEncode=URLEncoder.encode(“10030812”);
字符串fromEncode=URLEncoder.encode(from);
字符串toEncode=URLEncoder.encode(to);
字符串catUrl=“/v1/vehicles/get make models.json?sort=”
+分拣编码
+“&过滤器=”
+过滤代码
+“&客户端id=”
+客户代码
+“&from=”
+fromcode;
genSig=新的GetSignature(catUrl,“acura”);
试一试{
signature=genSig.getUrlFromString();
}捕获(InvalidKeyException e1){
//TODO自动生成的捕捉块
e1.printStackTrace();
}捕获(无算法异常e1){
//TODO自动生成的捕捉块
e1.printStackTrace();
}
//jsonString=
//GetJSonString(“http://api.highgearmedia.com/v1/vehicles/get-models.json?make=acura&client-id=10030812&signature=LWQbdAlJVxlXZ1VO2mfqAA==”;
//字符串签名码=
//URLEncoder.encode(签名);
字符串urlEncode=URLEncoder.encode(catUrl
+“&signature=”+签名);
jsonString=GetJSONSTRING(“http://apibeta.highgearmedia.com"
+catUrl+“&signature=“+signature”);
System.out.println(“json类别:=>”
class DemoAdapterCat extends EndlessAdapter {
        ImageLoader image = new ImageLoader(ResearchList.this);
        private RotateAnimation rotate = null;
        ArrayList<String> tempListNamesCat = new ArrayList<String>();
        ArrayList<String> tempListImagesCat = new ArrayList<String>();
        ArrayList<String> tempListYearCat1 = new ArrayList<String>();
        ArrayList<String> tempListYearCat2 = new ArrayList<String>();
        ArrayList<String> tempListmpgCat1 = new ArrayList<String>();
        ArrayList<String> tempListmpgCat2 = new ArrayList<String>();
        ArrayList<String> tempListpriceCat1 = new ArrayList<String>();
        ArrayList<String> tempListpriceCat2 = new ArrayList<String>();
        ArrayList<String> tempListRatingCat1 = new ArrayList<String>();
        ArrayList<String> tempListRatingCat2 = new ArrayList<String>();

        DemoAdapterCat() {
            super(new CategoryListLazyAdapter(ResearchList.this,
                    countriesSubCat, imagesSubCat, YearSubCat1, YearSubCat2,
                    mpgSubCat1, mpgSubCat2, priceSubCat1, priceSubCat2,
                    ratingSubCat1, ratingSubCat2));
            /*Utility util = new Utility();
            util.setListViewHeightBasedOnChildren(lvCategory);*/
            rotate = new RotateAnimation(0f, 360f, Animation.RELATIVE_TO_SELF,
                    0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
            rotate.setDuration(600);
            rotate.setRepeatMode(Animation.RESTART);
            rotate.setRepeatCount(Animation.INFINITE);
        }

        /*
         * @Override public int getCount() { return
         * brandList.getDisplayNames().size(); //return count+=10; }
         */
        @Override
        protected View getPendingView(ViewGroup parent) {
            row = getLayoutInflater().inflate(R.layout.categorylist, null);

            child = row.findViewById(R.id.tv_CategoryItem_Name);
            child.setVisibility(View.GONE);
            child = row.findViewById(R.id.tv_CategoryItem_MPG1);
            child.setVisibility(View.GONE);
            child = row.findViewById(R.id.tv_CategoryItem_MPG2);
            child.setVisibility(View.GONE);
            child = row.findViewById(R.id.tv_CategoryItem_Price1);
            child.setVisibility(View.GONE);
            child = row.findViewById(R.id.tv_CategoryItem_Price2);
            child.setVisibility(View.GONE);
            child = row.findViewById(R.id.tv_CategoryItem_Rating1);
            child.setVisibility(View.GONE);
            child = row.findViewById(R.id.tv_CategoryItem_Rating2);
            child.setVisibility(View.GONE);
            child = row.findViewById(R.id.tv_CategoryItem_Year1);
            child.setVisibility(View.GONE);
            child = row.findViewById(R.id.tv_CategoryItem_Year2);
            child.setVisibility(View.GONE);
            child = row.findViewById(R.id.linear_CategoryList_itemlayer1);
            child.setVisibility(View.GONE);
            child = row.findViewById(R.id.linear_CategoryList_itemlayer2);
            child.setVisibility(View.GONE);
            /*
             * child = row.findViewById(R.id.img_CategoryItem);
             * child.setVisibility(View.GONE); child =
             * row.findViewById(R.id.img_CategoryItem_Arrow);
             * child.setVisibility(View.GONE);
             */

            /*
             * child = row.findViewById(R.id.linear_main_MPG);
             * child.setVisibility(View.GONE);
             */
            child = row.findViewById(R.id.throbber);
            child.setVisibility(View.VISIBLE);
            child.startAnimation(rotate);

            return (row);
        }

        @Override
        protected boolean cacheInBackground() {
            //count += 10;
            SystemClock.sleep(100000);
            tempListNamesCat.clear();
            tempListImagesCat.clear();
            tempListmpgCat1.clear();
            tempListmpgCat2.clear();
            tempListpriceCat1.clear();
            tempListpriceCat2.clear();
            tempListYearCat1.clear();
            tempListYearCat2.clear();
            tempListRatingCat1.clear();
            tempListRatingCat2.clear();
//          countriesSubCat.clear();
//          imagesSubCat.clear();
//          YearSubCat1.clear();
//          YearSubCat2.clear();
//          mpgSubCat1.clear();
//          mpgSubCat2.clear();
//          priceSubCat1.clear();
//          priceSubCat2.clear();
//          ratingSubCat1.clear();
//          ratingSubCat2.clear();

            int lastOffset = getLastOffset();
            if (lastOffset < LIST_SIZE) {
                int limit = lastOffset + BATCH_SIZE;
                for (int i = (lastOffset + 1); (i <= limit && i < LIST_SIZE); i++) {
                    tempListNamesCat.add(coll.getDisplayNames().get(i));
                    tempListImagesCat.add(coll.getImages().get(i));
                    tempListmpgCat1.add(coll.getMpg().get(i));
                    tempListmpgCat2.add(coll.getMpg().get(i + 1));
                    tempListpriceCat1.add(coll.getPrice().get(i));
                    tempListpriceCat2.add(coll.getPrice().get(i + 1));
                    tempListRatingCat1.add(coll.getRating().get(i));
                    tempListRatingCat2.add(coll.getRating().get(i + 1));
                    tempListYearCat1.add(coll.getYears().get(i));
                    tempListYearCat2.add(coll.getYears().get(i + 1));
                }

                setLastOffset(limit);

                if (limit < LIST_SIZE) {
                    // return true;
                    return (getWrappedAdapter().getCount() < coll
                            .getDisplayNames().size());
                } else {
                    return false;
                }
            } else {
                return false;
            }
        }

        @Override
        protected void appendCachedData() {

            @SuppressWarnings("unchecked")
            // Activity activity = this;
            // ArrayAdapter<String> arrAdapterNew =
            // (ArrayAdapter<String>)getWrappedAdapter();
            CategoryListLazyAdapter arrAdapterNewCategory = (CategoryListLazyAdapter) getWrappedAdapter();
            // int listLen = tempList.size();
            // int listLen = tempListNames.size();
            countriesSubCat.addAll(tempListNamesCat);
            imagesSubCat.addAll(tempListImagesCat);
            mpgSubCat1.addAll(tempListmpgCat1);
            mpgSubCat2.addAll(tempListmpgCat2);
            priceSubCat1.addAll(tempListpriceCat1);
            priceSubCat2.addAll(tempListpriceCat2);
            ratingSubCat1.addAll(tempListRatingCat1);
            ratingSubCat2.addAll(tempListRatingCat2);
            YearSubCat1.addAll(tempListYearCat1);
            YearSubCat2.addAll(tempListYearCat2);
            arrAdapterNewCategory.notifyDataSetChanged();
            /*Utility util = new Utility();
            util.setListViewHeightBasedOnChildren(lvCategory);*/
            /*
             * for(int i=0; i<listLen; i++){ //
             * arrAdapterNew.add(tempList.get(i)); }
             */
        }
    }