在我的应用中,它有自定义ListView'
。 ListView
包含图片按钮。目前,如果用户使用Android手机或平板电脑,他们可以选择并按下此按钮...
但是如果他们使用例如使用遥控器的火棒我就不能选择它。如何确保我可以滚动浏览列表,同时确保在使用遥控器时滚动按钮?
我的custom.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<TextView
android:text="TextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/titleapp"
android:textSize="20dp"
android:textColor="@drawable/button_textcolour"
android:layout_marginLeft="6dp"
android:layout_marginRight="6dp"
android:layout_marginTop="12dp"
android:layout_alignParentTop="true"
android:layout_toEndOf="@+id/img" />
<TextView
android:text="TextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/detail"
android:layout_margin="6dp"
android:textSize="15dp"
android:layout_below="@+id/titleapp"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_toRightOf="@+id/img"
android:layout_toEndOf="@+id/img"
android:textColor="@drawable/button_textcolour"/>
<ImageView
android:layout_width="45dp"
android:padding="5dp"
android:id="@+id/img"
android:scaleType="fitCenter"
android:cropToPadding="true"
android:adjustViewBounds="true"
android:layout_height="45dp"
android:layout_alignBottom="@+id/detail"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/downloads"
android:id="@+id/downloadcounttext"
android:layout_below="@+id/detail"
android:layout_alignEnd="@+id/detail"
android:layout_marginRight="50dp"
android:textColor="@drawable/button_textcolour"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="0"
android:layout_marginLeft="5dp"
android:id="@+id/counterdl"
android:layout_below="@+id/detail"
android:layout_alignEnd="@+id/detail"
android:layout_marginEnd="37dp"
android:textColor="@drawable/button_textcolour"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/date_added"
android:id="@+id/dateaddedtxt"
android:layout_below="@+id/detail"
android:layout_alignStart="@+id/detail"
android:textColor="@drawable/button_textcolour"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:text="01/01/0000"
android:id="@+id/datetext"
android:layout_below="@+id/detail"
android:layout_toEndOf="@+id/dateaddedtxt"
android:textColor="@drawable/button_textcolour"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Report?"
android:paddingRight="5dp"
android:layout_alignTop="@+id/img"
android:layout_toStartOf="@+id/report"
android:layout_alignParentTop="true"
android:layout_margin="5dp" />
//HERE I WANT THIS BUTTON ON EVERY ITEM TO BE ABLE TO GAIN FOCUS WITH IN THE LIST
<ImageButton
android:layout_margin="5dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/report"
android:background="@drawable/ic_sentiment_dissatisfied_black_24dp"
android:layout_alignEnd="@+id/detail" />
我的BaseAdapter中的方法允许选择按钮
public View getView(final int position, View convertView, ViewGroup parent) { final View row;
if (convertView == null) {
row = LayoutInflater.from(parent.getContext()).inflate(R.layout.custom, parent, false);
} else {
row = convertView;
}
report = row.findViewById(R.id.report);
report.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
title.setText(Title[position]);
String getappname = title.getText().toString();
if (getappname!= null){
Log.i("Bad App ", getappname);