アンドロイドアプリをプログラミングしているうちにここで立ち往生しました。ListViewとTableLayoutでOnItemClickListenerが機能しません
アダプター(Extends BaseAdapter)に基づいてアイテムのリストを作成しました。これは、アイテムの必要な配置のためにTableLayoutのアイテムを表示します。その後、私はonItemClickListenerを追加したが、何も...
ActivityNews.xml起こりません:
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
>
<android.support.v7.widget.Toolbar
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:id="@+id/news_toolbar"
android:elevation="4dp"
android:background="@color/colorPrimary"
>
</android.support.v7.widget.Toolbar>
<ListView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/news_toolbar"
android:id="@+id/newslist"
android:background="@color/colorBackground"
></ListView>
</RelativeLayout>
その後、これはnews_list_view.xml
<android.support.v4.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:padding="6dp"
android:background="@color/colorBackground"
android:clickable="false"
android:focusable="false"
android:focusableInTouchMode="false"
android:descendantFocusability="blocksDescendants"
>
<ImageView android:id="@+id/news_image"
android:layout_alignParentStart="true"
android:layout_marginEnd="6dp"
android:layout_height="60dp"
android:layout_width="60dp"
android:clickable="false"
android:focusable="false"
android:layout_gravity="center"
android:focusableInTouchMode="false"
/>
<TableLayout
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:clickable="false"
android:focusable="false"
>
<TableRow
android:clickable="false"
android:focusable="false">
<TextView android:id="@+id/news_date"
android:layout_marginTop="4dp"
android:layout_marginRight="4dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="@color/colorDate"
android:layout_toRightOf="@id/news_image"
android:clickable="false"
android:focusable="false"
android:focusableInTouchMode="false"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textIsSelectable="false"
/>
<TextView android:id="@+id/news_type"
android:layout_marginTop="4dp"
android:layout_width="match_parent"
android:layout_toRightOf="@id/news_date"
android:layout_height="wrap_content"
android:textColor="@color/colorSubHeadline"
android:clickable="false"
android:focusable="false"
android:focusableInTouchMode="false"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textIsSelectable="false"
/>
</TableRow>
<TableRow
android:clickable="false"
android:focusable="false">
<TextView android:id="@+id/news_headline"
android:layout_marginTop="4dp"
android:textAppearance="?android:attr/textAppearanceMedium"
android:layout_width="wrap_content"
android:layout_below="@id/news_type"
android:layout_height="wrap_content"
android:textColor="@color/colorHeadline"
android:layout_span="2"
android:clickable="false"
android:focusable="false"
android:focusableInTouchMode="false"
android:textIsSelectable="false"/>
</TableRow>
</TableLayout>
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
とNewsActivity
からの抜粋ですlv = (ListView) findViewById(R.id.newslist);
adapter = new NewsAdapter(this);
lv.setAdapter(adapter);
lv.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Toast.makeText(NewsActivity.this, "You Clicked ", Toast.LENGTH_SHORT).show();
}
});
アイデア?
それについて研究している間、私は、ListViewの下の最初のレイアウトのために偽=クリック可能かdescendantFocusabilityの設定のようなヒントを見つけましたが、どれも働いた...
ありがとう!
ダニエルあなたが期待しているリストビューだけでクリックイベントを登録していない項目の選択を変更するためにクリックするよう指示CHOICE_MODE_SINGLE
を使用している
を削除することができますか? –