Listview在setcontentview()中变得模棱两可

时间:2014-08-07 10:33:00

标签: java android xml

我希望一个活动水平包含2个列表视图...我知道我编码正确但问题是现在每当进入setcontenct视图时它会找到一个带有这样数据的xml .......... 。 但现在我试图调试我的项目。它无法在setcontentview()

中找到列表
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:padding="5dp" >

    <TextView
        android:id="@+id/title_compare"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:padding="5dp"
        android:text="College Compare"
        android:textAppearance="@android:style/TextAppearance.Medium"
        android:textStyle="bold" />

    <View
        android:layout_width="fill_parent"
        android:layout_height="2dp"
        android:layout_marginTop="3dp"
        android:background="#000" />

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="5dp"
        android:orientation="horizontal"
        android:weightSum="3" >

        <TextView
            android:layout_width="0dip"
            android:layout_height="wrap_content"
            android:layout_marginRight="3dp"
            android:layout_weight="1"
            android:text="1st College"
            android:textAppearance="@android:style/TextAppearance.Small"
            android:typeface="sans" />

        <TextView
            android:id="@+id/col1_compare"
            android:layout_width="0dip"
            android:layout_height="wrap_content"
            android:layout_weight="2"
            android:text=""
            android:textAppearance="@android:style/TextAppearance.Small"
            android:typeface="serif" />
    </LinearLayout>

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:weightSum="3" >

        <TextView
            android:layout_width="0dip"
            android:layout_height="wrap_content"
            android:layout_marginRight="3dp"
            android:layout_weight="1"
            android:text="2nd College"
            android:textAppearance="@android:style/TextAppearance.Small"
            android:typeface="sans" />

        <TextView
            android:id="@+id/col2_compare"
            android:layout_width="0dip"
            android:layout_height="wrap_content"
            android:layout_weight="2"
            android:textAppearance="@android:style/TextAppearance.Small"
            android:typeface="serif" />
    </LinearLayout>

    <View
        android:layout_width="fill_parent"
        android:layout_height="2dp"
        android:layout_marginTop="3dp"
        android:background="#000" />

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:padding="5dp"
        android:weightSum="3" >

        <TextView
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_marginRight="3dp"
            android:layout_weight="1"
            android:textAppearance="@android:style/TextAppearance.Small" />

        <TextView
            android:id="@+id/t26"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_marginRight="3dp"
            android:layout_weight="1"
            android:text="1st College"
            android:textAppearance="@android:style/TextAppearance.Small"
            android:textStyle="bold" />

        <TextView
            android:id="@+id/t27"
            android:layout_width="0dip"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="2nd College"
            android:textAppearance="@android:style/TextAppearance.Small"
            android:textStyle="bold" />
    </LinearLayout>

    <View
        android:layout_width="fill_parent"
        android:layout_height="2dp"
        android:layout_marginTop="3dp"
        android:background="#000" />

    <ScrollView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" >

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical" >

            <LinearLayout
                android:layout_width="fill_parent"
                android:layout_height="match_parent"
                android:orientation="horizontal"
                android:padding="5dp"
                android:weightSum="3" >

                <TextView
                    android:layout_width="0dip"
                    android:layout_height="wrap_content"
                    android:layout_marginRight="3dp"
                    android:layout_weight="0.75"
                    android:text="Estd. In"
                    android:textAppearance="@android:style/TextAppearance.Small" />

                <TextView
                    android:id="@+id/estd_1"
                    android:layout_width="0dip"
                    android:layout_height="wrap_content"
                    android:layout_marginRight="3dp"
                    android:layout_weight="1.12"
                    android:textAppearance="@android:style/TextAppearance.Small"
                    android:typeface="serif" />

                <TextView
                    android:id="@+id/estd_2"
                    android:layout_width="0dip"
                    android:layout_height="wrap_content"
                    android:layout_weight="1.12"
                    android:textAppearance="@android:style/TextAppearance.Small"
                    android:typeface="serif" />
            </LinearLayout>

            <LinearLayout
                android:layout_width="fill_parent"
                android:layout_height="match_parent"
                android:orientation="horizontal"
                android:padding="5dp"
                android:weightSum="3" >

                <TextView
                    android:layout_width="0dip"
                    android:layout_height="wrap_content"
                    android:layout_marginRight="3dp"
                    android:layout_weight="0.75"
                    android:text="Affiliation"
                    android:textAppearance="@android:style/TextAppearance.Small" />

                <TextView
                    android:id="@+id/aff_1"
                    android:layout_width="0dip"
                    android:layout_height="wrap_content"
                    android:layout_marginRight="3dp"
                    android:layout_weight="1.12"
                    android:textAppearance="@android:style/TextAppearance.Small"
                    android:typeface="serif" />

                <TextView
                    android:id="@+id/aff_2"
                    android:layout_width="0dip"
                    android:layout_height="wrap_content"
                    android:layout_weight="1.12"
                    android:textAppearance="@android:style/TextAppearance.Small"
                    android:typeface="serif" />
            </LinearLayout>

            <LinearLayout
                android:layout_width="fill_parent"
                android:layout_height="match_parent"
                android:orientation="horizontal"
                android:padding="5dp"
                android:weightSum="3" >

                <TextView
                    android:layout_width="0dip"
                    android:layout_height="wrap_content"
                    android:layout_marginRight="3dp"
                    android:layout_weight="0.75"
                    android:text="Infrast."
                    android:textAppearance="@android:style/TextAppearance.Small" />

                <TextView
                    android:id="@+id/infrast_1"
                    android:layout_width="0dip"
                    android:layout_height="wrap_content"
                    android:layout_marginRight="3dp"
                    android:layout_weight="1.12"
                    android:textAppearance="@android:style/TextAppearance.Small"
                    android:typeface="serif" />

                <TextView
                    android:id="@+id/infrast_2"
                    android:layout_width="0dip"
                    android:layout_height="wrap_content"
                    android:layout_weight="1.12"
                    android:textAppearance="@android:style/TextAppearance.Small"
                    android:typeface="serif" />
            </LinearLayout>

            <LinearLayout
                android:layout_width="fill_parent"
                android:layout_height="match_parent"
                android:orientation="horizontal"
                android:padding="5dp"
                android:weightSum="3" >

                <TextView
                    android:layout_width="0dip"
                    android:layout_height="wrap_content"
                    android:layout_marginRight="3dp"
                    android:layout_weight="0.75"
                    android:text="Placemnt"
                    android:textAppearance="@android:style/TextAppearance.Small" />

                <TextView
                    android:id="@+id/placement_1"
                    android:layout_width="0dip"
                    android:layout_height="wrap_content"
                    android:layout_marginRight="3dp"
                    android:layout_weight="1.12"
                    android:textAppearance="@android:style/TextAppearance.Small"
                    android:typeface="serif" />

                <TextView
                    android:id="@+id/placement_2"
                    android:layout_width="0dip"
                    android:layout_height="wrap_content"
                    android:layout_weight="1.12"
                    android:textAppearance="@android:style/TextAppearance.Small"
                    android:typeface="serif" />
            </LinearLayout>

            <LinearLayout
                android:layout_width="fill_parent"
                android:layout_height="match_parent"
                android:orientation="horizontal"
                android:padding="5dp"
                android:weightSum="3" >

                <TextView
                    android:layout_width="0dip"
                    android:layout_height="wrap_content"
                    android:layout_marginRight="3dp"
                    android:layout_weight="0.75"
                    android:gravity="center"
                    android:text="@string/cnf"
                    android:textAppearance="@android:style/TextAppearance.Small" />

                <ListView
                    android:id="@+id/list_1"
                    android:layout_width="0dip"
                    android:layout_height="wrap_content"
                    android:layout_marginRight="3dp"
                    android:layout_weight="1.12"
                    android:divider="#000"
                    android:dividerHeight="0.5dp"
                    android:typeface="serif" />

                <ListView
                    android:id="@+id/list_2"
                    android:layout_width="0dip"
                    android:layout_height="wrap_content"
                    android:layout_weight="1.12"
                    android:divider="#000"
                    android:dividerHeight="0.5dp"
                    android:typeface="serif" />
            </LinearLayout>
        </LinearLayout>
    </ScrollView>

</LinearLayout>




 - public class Comparision extends ListActivity{

                @Override
            public void onCreate(Bundle savedInstanceState) {
                super.onCreate(savedInstanceState);

                comparelist_1 = new ArrayList<HashMap<String, String>>();
                comparelist_2 = new ArrayList<HashMap<String, String>>();

                clg1=Comparision1.c1;
                clg2=Comparision1.c2;
                setContentView(R.layout.college_compare);

                TextView tv1=(TextView) findViewById(R.id.col1_compare);
                TextView tv2=(TextView) findViewById(R.id.col2_compare);

                tv1.setText(clg1);
                tv2.setText(clg2);

                new getCompare().execute();
            }   

            class getCompare extends AsyncTask<String,String,String>{
                @Override
                protected void onPreExecute() {
                    super.onPreExecute();
                ........
                }




                @Override
                protected String doInBackground(String... params) {




          // ------------- THis is for the listview---------

           if (jsonString2 != null ) {
                            try{                    


                                JSONObject jsonObject_3= new JSONObject(jsonString2);
                                courses = jsonObject_3.getJSONArray(TAG_JSONARRAY1);

            /*      ---------       Colleges Compare url_2a   --------  */

                                for (int i = 0; i < courses.length() ; i++) {

                                    JSONObject jsonObject = courses.getJSONObject(i);

                                    String course_1=jsonObject.getString("course");

                                    String fee_1=jsonObject.getString("fee");

                    HashMap<String, String> Compare1 = new HashMap<String, String>(); 
                                    Compare1.put(C1, course_1);
                                    Compare1.put(C2, fee_1);

                                    comparelist_1.add(Compare1);

                                }
                                //  Collections.sort(suggest);
                            }catch(JSONException e){
                                Log.w("Error", e.getMessage());
                            }

                        }
                        if (jsonString3 != null ) {
                            try{                    


                                JSONObject jsonObject_4= new JSONObject(jsonString3);
                                courses1 = jsonObject_4.getJSONArray(TAG_JSONARRAY1);

         /*         -------------------       Colleges Compare url_2a   --------  */

                                for (int i = 0; i < courses1.length() ; i++) {

                                    JSONObject jsonObject = courses1.getJSONObject(i);

                                    String course_2=jsonObject.getString("course");

                                    String fee_2=jsonObject.getString("fee");

                        HashMap<String, String> Compare2 = new HashMap<String, String>(); 
                                    Compare2.put(C3, course_2);
                                    Compare2.put(C4, fee_2);

                                    comparelist_2.add(Compare2);

                                }
                                //  Collections.sort(suggest);
                            }catch(JSONException e){
                                Log.w("Error", e.getMessage());
                            }

                        }

                    return null;
                }

                @Override
                protected void onPostExecute(String result) {
                    super.onPostExecute(result);

                ListAdapter adapter1 = new SimpleAdapter(Comparision.this, comparelist_1,
                            R.layout.course_fee, new String[] { C1,C2 },
                                    new int[] { R.id.coursetv_c_f,R.id.feetv_c_f });
                    setProgressBarVisibility(true);
                    setListAdapter(adapter1);


                ListAdapter adapter2 = new SimpleAdapter(Comparision.this,comparelist_2,
                        R.layout.course_fee, new String[] { C3,C3 },
                                    new int[] { R.id.coursetv_c_f,R.id.feetv_c_f });
                //  setProgressBarVisibility(true);
                    setListAdapter(adapter2);


                }


            }

           }

0 个答案:

没有答案