Ошибка в использовании ListView в ListActivity - PullRequest
0 голосов
/ 29 сентября 2011

У меня проблемы с использованием ListActivity.Если я изменяю расширение класса с ListActivity на Activity, он работает нормально.Но тогда проблема в том, как я буду реализовывать onListItemClick.Возможно, это небольшая ошибка, которую я мог бы сделать, но я не в состоянии отследить ее.

public class Warehouse extends ListActivity {

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        System.out.println("Inside Warehouse");
        setContentView(R.layout.warehous);

        LinearLayout linear = (LinearLayout) findViewById(R.id.linearfullview);
        drawable = setBitMap(background_image);
        linear.setBackgroundDrawable(drawable);
    String[] names = new String[] { "Inventory Ageing",
                "Inventory Carring Cost", "Inventory Turns" };


        LinearLayout linearList = (LinearLayout) findViewById(R.id.linearlist);
        drawable = setBitMap(list_image);
        linearList.setBackgroundDrawable(drawable);
      this.setListAdapter(new ArrayAdapter<String>(this,R.layout.warehouse_list,names));         
        // ListView lv = getListView(); lv.setTextFilterEnabled(true);

    }

    public Drawable setBitMap(String imagename) {
        Bitmap image = BitmapFactory.decodeStream(getClass()
                .getResourceAsStream(("/com/image/" + imagename + ".png")));
        drawable = new BitmapDrawable(image);
        return drawable;
    }

    protected void onListItemClick(ListView l, View v, int position, long id) {
        super.onListItemClick(l, v, position, id); 
        Object o = this.getListAdapter().getItem(position);
        String keyword = o.toString();

        }
        } 
    }

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_height="fill_parent" android:orientation="horizontal"
    android:layout_width="fill_parent">
    <LinearLayout android:layout_width="fill_parent"
        android:id="@+id/linearfullview" android:layout_height="400sp"
        android:layout_alignParentTop="true" />

    <LinearLayout android:layout_width="wrap_content"
        android:layout_height="180sp" android:layout_alignParentBottom="true"
        android:layout_marginTop="20sp">


        <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
            android:id = "@+id/linearlist" android:layout_height="wrap_content" android:layout_width="wrap_content"
            android:paddingLeft="2dp" android:paddingRight="2dp" android:gravity="bottom"
            android:layout_marginTop="30dp">
            <ListView android:id="@android:id/list" android:layout_width="100dip" android:layout_height="wrap_content"></ListView>
            </LinearLayout>

        <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
            android:layout_height="wrap_content" android:layout_width="wrap_content"
            android:paddingLeft="2dp" android:paddingRight="2dp"
            android:paddingTop="4dp" android:gravity="bottom"
            android:layout_marginTop="30dp">
            <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
                android:layout_height="wrap_content" android:id="@+id/linearFirst"
                android:layout_alignParentLeft="true" android:layout_width="wrap_content"
                android:paddingLeft="2dp" android:paddingRight="2dp"
                android:paddingTop="4dp" android:gravity="bottom"
                android:layout_marginTop="30dp" android:visibility="invisible">
                <com.widget.WheelView
                    android:id="@+id/firstWheel" android:layout_height="wrap_content"
                    android:layout_width="100dp" />
            </LinearLayout>
            <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
                android:layout_height="wrap_content" android:id="@+id/linearSecond"
                android:layout_width="wrap_content" android:paddingLeft="2dp"
                android:paddingRight="2dp" android:layout_alignParentRight="true"
                android:paddingTop="4dp" android:gravity="bottom"
                android:layout_marginTop="30dp" android:visibility="invisible">
                <com.widget.WheelView
                    android:id="@+id/secondWheel" android:layout_height="wrap_content"
                    android:layout_width="100dp" />
            </LinearLayout>
            <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
                android:layout_height="wrap_content" android:id="@+id/linearThird"
                android:layout_width="wrap_content" android:paddingLeft="2dp"
                android:paddingRight="2dp" android:paddingTop="4dp" android:gravity="bottom"
                android:layout_marginTop="30dp" android:layout_alignParentLeft="true"
                android:visibility="invisible">
                <com.widget.WheelView
                    android:id="@+id/thirdWheel" android:layout_height="wrap_content"
                    android:layout_width="200dp" />
            </LinearLayout>
        </RelativeLayout>
    </LinearLayout>
</RelativeLayout> 

Ответы [ 3 ]

0 голосов
/ 29 сентября 2011

Можете ли вы использовать

public class Warehouse extends Activity implements onListItemClick

вместо?

0 голосов
/ 29 сентября 2011

ссылка http://www.vogella.de/articles/AndroidListView/article.html ссылка.Есть небольшая ошибка, которую ты совершаешь

Best of Luck ...

0 голосов
/ 29 сентября 2011

если вы расширяете ListActivity, тогда вы должны взять Listview в main.xml с @+android:id/list

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_height="fill_parent" android:orientation="horizontal"
    android:layout_width="fill_parent">
    <ListView android:id="@android:id/list"
               android:layout_width="match_parent"
               android:layout_height="match_parent" />
...
...