我正在为Android电视开发应用程序。 dpad方向导航键有效,但不能输入键(中间键)。 我对dpad编码不了解。 请帮忙。
custom adapter.java
public class CustomAdapter extends BaseAdapter {
Context c;
ArrayList<Spacecraft> spacecrafts;
public CustomAdapter(Context c, ArrayList<Spacecraft> spacecrafts) {
this.c = c;
this.spacecrafts = spacecrafts;
}
@Override
public int getCount() {
return spacecrafts.size();
}
@Override
public Object getItem(int position) {
return spacecrafts.get(position);
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
if(convertView==null)
{
convertView= LayoutInflater.from(c).inflate(R.layout.model,parent,false);
}
TextView nameTxt= (TextView) convertView.findViewById(R.id.nameTxt);
ImageView img= (ImageView) convertView.findViewById(R.id.spacecraftImage);
final Spacecraft s= (Spacecraft) this.getItem(position);
nameTxt.setText(s.getName());
PicassoClient.downloadImage(c, s.getImageUrl(), img);
convertView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Toast toast = Toast.makeText(c.getApplicationContext(), "This is a message displayed", Toast.LENGTH_SHORT); toast.show();
openDetailACtivity(s.getName(),s.getPropellant(),s.getDescription(),s.getImageUrl());
}
});
return convertView;
}
private void openDetailACtivity(String name,String propellant,String description,String imageUrl)
{
Intent i=new Intent(c, channel.class);
//PACK DATA
i.putExtra("NAME_KEY",name);
i.putExtra("PROPELLANT_KEY",propellant);
i.putExtra("DESCRIPTION_KEY",description);
i.putExtra("IMAGEURL_KEY",imageUrl);
c.startActivity(i);
}
}
我试图单击网格视图中的ImageView。 我可以在模拟器上用鼠标单击图像,但不能用Dpad单击图像。 而我的xml代码是
model.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal" android:layout_width="match_parent"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:layout_margin="10dp"
card_view:cardCornerRadius="5dp"
card_view:cardElevation="5dp"
android:layout_height="100dp">
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:layout_width="fill_parent"
android:imeOptions="actionGo"
android:layout_height="fill_parent"
android:id="@+id/spacecraftImage"
android:background="@drawable/background"
android:src="@drawable/play" />
<TextView
android:id="@+id/nameTxt"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:padding="1dp"
android:text="Name"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="@color/colorAccent" />
</LinearLayout>
</android.support.v7.widget.CardView>