我正在使用无限listView制作一个应用程序,开始时列表只有10个元素,但是当用户滚动到结尾时,它又添加了10个元素,依此类推

我想最后添加进度条,以便在添加元素之前显示进度条。为此,我使用这样的addFooterView

 pro = (ProgressBar)rootView.findViewById(R.id.progress);
 ListView lv = ((ListView)rootView.findViewById(R.id.listViewInternship));
   lv.addFooterView(pro);


lv.addFooterView(pro)给出以下异常

java.lang.ClassCastException: android.widget.RelativeLayout$LayoutParams cannot be cast to android.widget.AbsListView$LayoutParams


有什么问题??

编辑

我查看的xml文件是

<?xml version="1.0" encoding="utf-8"?><RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/progress"
>
<ProgressBar
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerHorizontal="true"
    android:layout_alignParentBottom="true" /></RelativeLayout>


请大家帮忙

我完整的Java代码

public class Internship extends Fragment {

int count = 0;
JSONParser jsonParser = new JSONParser();
public Internship() {
}

//urls of php files
private static final String url_of_showing_all_internships = "some url";

Boolean flag_loading=false;
ArrayList<DataOfInternship> internshipArrayList ;
ArrayAdapter<DataOfInternship> adapter;
ProgressBar pro ;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState) {
    View rootView =inflater.inflate(R.layout.fragment_internship, container, false);

    count = 1;
    pro = (ProgressBar)rootView.findViewById(R.id.progress);
    internshipArrayList =  new ArrayList<>();

    additems();

    adapter = new ArrayAdapter<DataOfInternship>(getActivity() , R.layout.internship_view,R.id.titleOfInternship,internshipArrayList){
        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            View row = super.getView(position, convertView, parent);

            ((TextView)row.findViewById(R.id.typeOfInternship)).setText(internshipArrayList.get(position).Type);
            ((TextView)row.findViewById(R.id.titleOfInternship)).setText(internshipArrayList.get(position).Name);
            ((TextView)row.findViewById(R.id.locationOfInternship)).setText(internshipArrayList.get(position).Location);
            ((TextView)row.findViewById(R.id.startDateOfInternship)).setText(internshipArrayList.get(position).StartDate);
            ((TextView)row.findViewById(R.id.stipendOfInternship)).setText(internshipArrayList.get(position).Stipend);
            ((TextView)row.findViewById(R.id.durationOfInternship)).setText(internshipArrayList.get(position).Duration);

            return  row;
        }
    };

    ListView lv = ((ListView)rootView.findViewById(R.id.listViewInternship));
    lv.addFooterView(pro);
    lv.setAdapter(adapter);
    lv.setOnScrollListener(new AbsListView.OnScrollListener() {
        public void onScrollStateChanged(AbsListView view, int scrollState) {


        }

        public void onScroll(AbsListView view, int firstVisibleItem,
                             int visibleItemCount, int totalItemCount) {

            if(firstVisibleItem+visibleItemCount == totalItemCount && totalItemCount!=0)
            {
                if(!flag_loading)
                {
                    flag_loading = true;
                    additems();
                    count+=10;
                }
            }
        }
    });

    return rootView;
}JSONArray internships = null;
private void additems() {

    new AsyncTask<Void , Void, Void>(){

        @Override
        protected void onPreExecute() {
            super.onPreExecute();
        }
        @Override
        protected Void doInBackground(Void... params) {

            //making parameters for sno
            List<NameValuePair> parameters = new ArrayList<NameValuePair>();
            parameters.add(new BasicNameValuePair("sno" , String.valueOf(count)));

            //making json object
            JSONObject json = jsonParser.makeHttpRequest(url_of_showing_all_internships, "POST", parameters);

            Log.e("count= "+count,json.toString());

            try {
                int success = json.getInt("success");
                if (success ==1){
                    internships = json.getJSONArray("internships");

                    for (int i = 0 ; i < internships.length(); i++){
                        JSONObject temp = internships.getJSONObject(i);

                        //making dataobject
                        String title = temp.getString("internship_title")
                                , type = temp.getString("internship_type")
                                ,location = temp.getString("location")
                                ,start_date = temp.getString("start_date")
                                ,duration = temp.getString("duration")
                                ,stipend = temp.getString("stipend")
                                ,description = temp.getString("dis")
                                ;

                        DataOfInternship tempData = new DataOfInternship(title,type,description,"",location,stipend,start_date,duration);
                        internshipArrayList.add(tempData);

                    }
                    flag_loading = false;


                }
                else publishProgress();
            } catch (JSONException e) {
                Log.e("json Exception" , e.toString());
            }
            return null;
        }

        @Override
        protected void onProgressUpdate(Void... values) {
            super.onProgressUpdate(values);
            Toast.makeText(getActivity(),"Connection not secure",Toast.LENGTH_SHORT).show();
        }

        @Override
        protected void onPostExecute(Void aVoid) {
            super.onPostExecute(aVoid);
            adapter.notifyDataSetChanged();
        }
    }.execute();

}


}

我知道那是一团糟,但有助于理解

提前致谢

最佳答案

得到它了
谢谢TinTran和Jay Shah有了您的解决方案

问题出在
lv.addFooterView(pro)

我应该在其中添加一个视图addFooterView而不是一个进度条

所以代码是

View view = inflater.inflate(R.layout.progressbar_view,null,false); lv.addFooterView(view);

代替lv.addFooterView(pro);

再次感谢大家

10-06 10:46