如果我的帖子不够清楚,请原谅我。
我有带有ImageView和TextView的GridView,它们由自定义适配器填充。
当我在GridView中突出显示某个项目并按下IR遥控(OK)按钮时,它只会返回统计按下的动画。
现在我尝试了一个KeyCode监听器,它返回键码数字,我发现除了OK按钮之外的所有KeyCodes都没有返回任何内容。
现在我也尝试了所有KeyCode事件,例如ENTER,DPAD_CENTER,ACTION_DOWN和OnTouchListeners都没有用。
我还将gridview xml中按下的标签stat添加到false。
无法在调试器中调试此应用,因为它是智能电视
ChannelListAdapter.java
package com.showhd.adapter;
import java.util.List;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.view.Display;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnTouchListener;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import com.nostra13.universalimageloader.core.ImageLoaderConfiguration;
import com.nostra13.universalimageloader.core.assist.FailReason;
import com.nostra13.universalimageloader.core.assist.ImageLoadingListener;
import com.showhd.R;
import com.showhd.common.Shared;
import com.showhd.data.TVChannel;
import com.showhd.stb.STBTV;
import com.showhd.stb.VStreaming;
@SuppressLint("ClickableViewAccessibility")
public class ChannelListAdapter extends ArrayAdapter<TVChannel>
{
private Context context;
private int layoutId;
private List<TVChannel> data = null;
public ChannelListAdapter(Context context, int layoutId, List<TVChannel> data) {
super(context, layoutId, data);
this.context = context;
this.layoutId = layoutId;
this.data = data;
Shared.imageLoader.init(ImageLoaderConfiguration
.createDefault(context));
}
@SuppressWarnings("deprecation")
public View getView(final int position, View convertView,
ViewGroup parent) {
final ViewHolder holder;
if (convertView == null) {
LayoutInflater inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = inflater.inflate(layoutId, parent, false);
holder = new ViewHolder();
holder.imageviewIcon = (ImageView) convertView
.findViewById(R.id.iv_channel_icon);
holder.textviewChannelCaption = (TextView) convertView.findViewById(R.id.tv_channel_caption);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
final ImageView imageView = holder.imageviewIcon;
Shared.imageLoader.displayImage(data.get(position).getIconUrl(), holder.imageviewIcon, Shared.options, new ImageLoadingListener() {
public void onLoadingStarted() {
}
public void onLoadingFailed(FailReason failReason) {
}
public void onLoadingComplete(Bitmap loadedImage) {
int realWidth = loadedImage.getWidth();
int realHeight = loadedImage.getHeight();
// Resize image
Display display = ((Activity)context).getWindowManager().getDefaultDisplay();
int screenWidth = display.getWidth();
int imageWidth = screenWidth / 10;
imageView.getLayoutParams().width = imageWidth;
imageView.getLayoutParams().height = (int)(((float)imageWidth / (float)realWidth) * realHeight);
}
public void onLoadingCancelled() {
}
});
holder.textviewChannelCaption.setText(data.get(position).getCaption());
convertView.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
STBTV.channelId = data.get(position).getId();
// VStreaming.streamVideo1(data.get(position).getStreamingUrl());
String g = data.get(position).getStreamingUrl();
Intent intent = new Intent(context,VStreaming.class);
intent.putExtra("Vpath", g);
context.startActivity(intent);
}
});
return convertView;
}
static class ViewHolder {
TextView textviewChannelCaption;
ImageView imageviewIcon;
}
}
stb_channel_item.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/list_item_selector"
android:gravity="center_vertical"
android:orientation="horizontal" >
<ImageView
android:id="@+id/iv_channel_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:state_pressed="false"
android:focusable="false"
android:contentDescription="@string/app_name"
android:padding="1.5dp"
android:scaleType="fitXY"/>
<TextView
android:id="@+id/tv_channel_caption"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:layout_weight="1"
android:textColor="@color/white"
android:textSize="25sp"
android:textIsSelectable="false"
android:textStyle="bold"
android:singleLine="false"
android:ellipsize="end" />
</LinearLayout>
stb_tv.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/bg_main"
android:orientation="vertical" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal" >
<LinearLayout
android:id="@+id/ll_packages"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_marginRight="2dp"
android:layout_weight="1"
android:orientation="vertical"
android:visibility="gone" >
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@color/bg_title"
android:gravity="center"
android:paddingBottom="5dp"
android:paddingTop="5dp"
android:text="@string/packages"
android:textColor="@color/Red"
android:textStyle="bold" />
<ListView
android:id="@+id/lv_packages"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
</ListView>
</LinearLayout>
<LinearLayout
android:id="@+id/ll_categories"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_marginRight="2dp"
android:layout_weight="1"
android:orientation="vertical" >
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@color/lawn_green"
android:gravity="center"
android:paddingBottom="5dp"
android:paddingTop="5dp"
android:alpha=".80"
android:text="@string/categories"
android:textColor="@color/white"
android:textStyle="bold" />
<ListView
android:id="@+id/lv_categories"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:height="?android:attr/listPreferredItemHeight"
android:textAlignment="textStart" >
</ListView>
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="0"
android:orientation="vertical" >
<ListView
android:id="@+id/lv_epgs"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:visibility="gone" >
</ListView>
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="3"
android:orientation="vertical" >
<GridView
android:id="@+id/gridView1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:numColumns="3"
android:verticalSpacing="25dp" >
</GridView>
</LinearLayout>
</LinearLayout>
</LinearLayout>