0

エントリのレイアウトを変更したListViewところ、clickListener が機能しなくなりました。修正方法と機能しなくなった理由がわかりません。

リストを埋めるコードは次のとおりです。

private void setList() {
        List<Subject> subjects = datasource.getAllSubjects();
        ArrayList<HashMap> cards = new ArrayList<HashMap>();


        for (int i=0; i < subjects.size(); i++) {
            HashMap card = new HashMap();
            card.put("listname", subjects.get(i).getSubject().toString());

            long count = cardsource.getNumberOfCardsOfSubject(subjects.get(i).getSubject().toString());
            card.put("count", "Number of Cards: " + count);
            cards.add(card);
        }

         SimpleAdapter sa = new SimpleAdapter(
                    getApplicationContext(),
                    (List<? extends Map<String, ?>>) cards,
                    R.layout.cards,
                    new String[] { "listname", "count",},
                    new int[] { R.id.CARD_SCREEN_NAME, R.id.CARD_TEXT}) {
                };

        listView.setAdapter(sa);
    }

次の XML ファイルを使用して、各エントリのレイアウトを定義します (サブ項目を追加したかったので、そのようにすることを選択しました)。

<?xml version="1.0" encoding="utf-8"?>
<!-- A row of tweet data for display -->
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:paddingBottom="20sp"
    android:orientation="vertical">

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

        <TextView
            android:id="@+id/CARD_SCREEN_NAME"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="AndroidZA"
            android:textSize="20sp"
            android:textStyle="bold"
            android:textColor="#000000" />

    </LinearLayout>

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

        <TextView android:id="@+id/CARD_TEXT"
            android:text="Hi, this is a tweet. It should be 140 characters or less"
            android:paddingRight="5dip"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:textColor="#000000"/>

    </LinearLayout>
</LinearLayout>

そして、これは私のクリックリスナーです:

listView.setOnItemClickListener(new OnItemClickListener() {

            @Override
            public void onItemClick(AdapterView<?> arg0, View arg1, int position, long id) {
                // TODO Auto-generated method stub
                Object item = listView.getAdapter().getItem(position);
                selectedItem = item.toString();

                goToDelete();
            }


        });

これは、goToDelete()私が new に移動するために使用する -MethodAcitityです。次の で選択した件名に関する情報が必要なので、Stringを と一緒に渡します。問題は、ClickListener でこれらの情報を正しく取得できない可能性があります。IntentActivity

Object item = listView.getAdapter().getItem(position);
selectedItem = item.toString(); 

しかし、それgoToDelete()がなくても は呼び出されません。誰かがこの問題で私を助けることができますか? さらに情報が必要な場合は、お知らせください。

4

0 に答える 0