有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

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

我希望一个活动包含两个列表视图水平。。。我知道我的编码是正确的,但现在的问题是,每当它转到setcontenct视图时,就会发现一个包含如下数据的xml。。。。。。。。。。。 但现在当我试着调试我的项目时。无法在setcontentview()中找到列表

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:安卓="http://schemas.安卓.com/apk/res/安卓"
    安卓:layout_width="match_parent"
    安卓:layout_height="match_parent"
    安卓:orientation="vertical"
    安卓:padding="5dp" >

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    <ScrollView
        安卓:layout_width="fill_parent"
        安卓:layout_height="wrap_content" >

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                <ListView
                    安卓:id="@+id/list_2"
                    安卓:layout_width="0dip"
                    安卓:layout_height="wrap_content"
                    安卓:layout_weight="1.12"
                    安卓:divider="#000"
                    安卓:dividerHeight="0.5dp"
                    安卓: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) 个答案