-1

我试图在 2 布局所做的相同活动中显示我的 ListView:main_activity.xml list_item.xml

通过遵循互联网上的教程,并通过在一个非常简单的相对布局中仅由一个 listView 组成的其他项目中解析 listView,列表显示。但是通过在更复杂的布局中处理/解析,显示问题仍然存在。

我确实没有错误,只是显示问题。

这是我的两个布局:

activity_main.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="left" >

<RelativeLayout
    android:id="@+id/homepageView"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_alignParentLeft="true"
    android:layout_alignParentRight="true"
    android:layout_below="@+id/searchView" >

    <ImageView
        android:id="@+id/imageView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_centerHorizontal="true"
        android:layout_marginBottom="15dp"
        android:adjustViewBounds="false"
        android:contentDescription="@string/premier_test_afficher_image"
        android:src="@drawable/ic_launcher" />

    <Button
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="55dp"
        android:text="@string/Clear_cache" />

    <TextView
        android:id="@+id/textView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_marginLeft="41dp"
        android:visibility="gone" />

</RelativeLayout>

<RelativeLayout
    android:id="@+id/searchView"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" >

    <EditText
        android:id="@+id/editText"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentRight="true"
        android:hint="@string/Search"
        android:imeOptions="actionSearch"
        android:singleLine="true" >

    </EditText>

    </RelativeLayout>

    <ListView
        android:id="@android:id/list"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/searchView" 
        android:layout_alignParentLeft="true"
        android:visibility="gone"> 

    </ListView>

list_item.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical">

    <TextView
        android:id="@+id/name"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:textSize="16sp"
        android:textStyle="bold"
        android:paddingTop="6dip"
        android:paddingBottom="2dip" />

    <TextView
        android:id="@+id/email"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:paddingBottom="2dip">
    </TextView>

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

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:gravity="left"
        android:textStyle="bold"
        android:text="@string/Mobile: " >
    </TextView>

    <TextView
        android:id="@+id/mobile"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textStyle="bold"
        android:gravity="left">
    </TextView>
    </LinearLayout>
</LinearLayout>

这是我的 Main_Activity.java 的部分代码

                    for(int j=0; j < suggests.length(); j++){
                    JSONObject ssjObj = suggests.getJSONObject(j);
                    /*Ne pas déplacer cette hashmap sinon elle se réinitialise à chaque j*/
                    HashMap<String, String> dataMap = new HashMap<String, String>();
                    dataMap.put(TAG_SCORE, ssjObj.getString(TAG_SCORE));
                    Log.i(DEBUG_TAG,ssjObj.getString(TAG_SCORE));
                    dataMap.put(TAG_TERM, ssjObj.getString(TAG_TERM));
                    Log.i(DEBUG_TAG,ssjObj.getString(TAG_TERM));
                    dataMap.put(TAG_LOC, ssjObj.getString(TAG_LOC));
                    Log.i(DEBUG_TAG,ssjObj.getString(TAG_LOC));
                    currentList.add(dataMap);
                    Log.i("currentList",currentList.toString());
                        currentDico.put(query, currentList);
                    Log.i("currentDico",currentDico.toString());

我告诉你我的currentList是什么

[
{
    score=980,
    loc=Genesis32: 27,
    term=Andhesaid,
    Jacob.
},
{
    score=969,
    loc=John4: 6,
    term=NowJacob'swellwasthere.
},
{
    score=965,
    loc=Genesis31: 25,
    term=ThenLabanovertookJacob.
},
{
    score=965,
    loc=Malachi1: 2,
    term=WasnotEsauJacob'sbrother?
},
{
    score=953,
    loc=Genesis37: 2,
    term=ThesearethegenerationsofJacob.
},
{
    score=953,
    loc=Micah1: 5,
    term=WhatisthetransgressionofJacob?
},
{
    score=949,
    loc=Genesis30: 10,
    term=AndZilpahLeah'smaidbareJacobason.
},
{
    score=945,
    loc=Genesis27: 36,
    term=Andhesaid,
    IsnotherightlynamedJacob?
},
{
    score=941,
    loc=Genesis30: 5,
    term=AndBilhahconceived,
    andbareJacobason.
},
{
    score=937,
    loc=Genesis30: 12,
    term=AndZilpahLeah'smaidbareJacobasecondson.
}
]

最后是我在postExecute方法上运行的 listAdapter

        runOnUiThread(new Runnable() {
        public void run() {

            ListAdapter adapter = new SimpleAdapter(MainActivity.this,
                                        currentList, 
                                        R.layout.list_item,
                                        new String[] { TAG_TERM, TAG_LOC, TAG_SCORE },
                                        new int[]{R.id.name, R.id.email, R.id.mobile });
            Log.i("onPostExecute","SimpleAdapter");
            setListAdapter(adapter);
            Log.i("onPostExecute", "adapter");
            }
        });
4

1 回答 1

0

好的,我找到了。代码中没有错误。我忘了考虑视图的初始可见性。

<ListView
    android:id="@android:id/list"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_below="@+id/searchView" 
    android:layout_alignParentLeft="true"
    android:visibility="gone"> 
</ListView>

我只是将它添加到代码中。

if(mListView.getVisibility() != View.VISIBLE){
mHomePage.setVisibility(View.GONE);    
mListView.setVisibility(View.VISIBLE);
myClickHandler(v);
}
于 2013-11-13T11:39:53.737 回答