gpt4 book ai didi

android - 在带 Remote 的 Android 电视中无法选择和单击动态 TextView

转载 作者:太空狗 更新时间:2023-10-29 14:02:10 26 4
gpt4 key购买 nike

我已经在 ListView 的行中创建了动态 TextView ,但是电视 Remote 无法聚焦 TextView ,我想知道 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;
}

最佳答案

这是在 RecyclerView 中吗?

对于 DPAD,除非您手动覆盖并编写 onKeyDown 方法,否则无法将焦点放在 TextView 上,该方法在敲击回车键时执行点击。

您可能想为整个 View 编写一个onClickListener,然后在检测到回车键时获取当前 View 并执行点击。

回收 View :

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

在你的 Activity 中:

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

关于android - 在带 Remote 的 Android 电视中无法选择和单击动态 TextView ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34758642/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com