动态文本视图无法在具有远程控制功能的Android电视中进行选择和点击

时间:2016-01-13 04:54:11

标签: android android-activity android-tv

我在listview的行中创建了动态文本视图,但该文本视图无法通过电视遥控器进行聚焦,我想知道textview是否有任何特定的属性,我需要设置?

此处的源代码:

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    final EventData item = list.get(position);
    ViewHolder holder = null;
    if (convertView == null) {
        holder = new ViewHolder();
        inflater = (LayoutInflater) ctx
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        convertView = inflater.inflate(R.layout.list_item_livesports, null);

        holder.nameTV = (TextView) convertView.findViewById(R.id.nameTV);
        holder.teamsTV = (TextView) convertView.findViewById(R.id.teamsTV);
        holder.startsTV = (TextView) convertView.findViewById(R.id.startTV);
        holder.channelLL = (TableLayout) convertView
                .findViewById(R.id.channelLL);
        holder.catIV = (ImageView) convertView.findViewById(R.id.catIV);
        convertView.setTag(holder);
    } else
        holder = (ViewHolder) convertView.getTag();

    holder.nameTV.setText(item.getName() + " : " + item.getTeams());
    holder.teamsTV.setText(item.getTeams());
    holder.startsTV.setText(item.getStarts());


    setDrawals(holder.catIV, item);

    TableRow tr_head = null;
    holder.channelLL.removeAllViews();
    for (int i = 0; i < item.linkList.size(); i++) {
        TextView v = new TextView(ctx);

        final Spanned name = Html.fromHtml("<font color='#0000FF'>"
                + item.linkList.get(i).channelName + "</font>");
        final String link = item.linkList.get(i).channelLink;
        v.setText(name);

        if (i == 0 || i == 2 || i == 4 || i == 6 || i == 8 || i == 10) {
            tr_head = new TableRow(ctx);
            tr_head.setLayoutParams(new LayoutParams(
                    LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
        }
        v.setPadding(20, 15, 20, 15);
        tr_head.addView(v);


        v.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                // Toast.makeText(ctx, name, 1).show();
                linkListener.onLinkClicked(link);

            }
        });
        if (i == 0 || i == 2 || i == 4 || i == 6 || i == 8 || i == 10)
            holder.channelLL.addView(tr_head, new TableLayout.LayoutParams(
                    LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));

    }

    return convertView;
}

1 个答案:

答案 0 :(得分:1)

这是RecyclerView吗?

使用DPAD时,除非您手动覆盖并编写在点击回车键时执行单击的onKeyDown方法,否则无法专注于TextView。

您可能希望为整个视图编写onClickListener,然后在检测到回车键时,获取当前视图并执行单击。

RecyclerView:

convertView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            //Do stuff
        }
    });

在你的活动中:

public boolean onKeyDown(int keyCode, KeyEvent event) {
  switch(keyCode) {
    case KeyEvent.KEYCODE_DPAD_CENTER:
            mRecyclerView.findViewHolderForAdapterPosition(index).itemView.performClick();
            break;
  }   
}