如何在android自定义适配器中创建trackballevent?
我正在使用以下代码为列表视图创建自定义适配器。 现在我想在其中使用轨迹球单击事件,但我不知道该怎么做,任何人都可以帮助我在自定义适配器中创建 ontracballevent 吗? 我尝试写几行但无法解决它。
public class EfficientAdapter extends BaseAdapter implements Filterable {
private LayoutInflater mInflater;
private Context context;
int pos;
public EfficientAdapter(Context context) {
mInflater = LayoutInflater.from(context);
this.context = context;
}
public View getView(final int position, View convertView, ViewGroup parent) {
ViewHolder holder;
convertView = mInflater.inflate(R.layout.adaptor_contentposts, null);
convertView.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
//点击功能 } });
MotionEvent event= MotionEvent.CREATOR.createFromParcel(null);
switch (event.getAction())
{
case MotionEvent.ACTION_DOWN:
//display click message
}
convertView.onTrackballEvent(event);
return convertView;
}
class ViewHolder {
TextView textLine;
TextView textLine2;
TextView PostedByAndPostedOn;
ImageButton ImgButton;
}
@Override
public Filter getFilter() {
return null;
}
@Override
public long getItemId(int position) {
return 0;
}
@Override
public int getCount() {
return ad_id.length;
}
@Override
public Object getItem(int position) {
return ad_id[position];
}
}
i am using following code to create custom adapter for listview.
now i want to use trackball click event in it but i dont know how to do that can any one help me out in creating ontracballevent in custom adapter?
i have tried writing few lines but not able to solve it.
public class EfficientAdapter extends BaseAdapter implements Filterable {
private LayoutInflater mInflater;
private Context context;
int pos;
public EfficientAdapter(Context context) {
mInflater = LayoutInflater.from(context);
this.context = context;
}
public View getView(final int position, View convertView, ViewGroup parent) {
ViewHolder holder;
convertView = mInflater.inflate(R.layout.adaptor_contentposts, null);
convertView.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
//click functionality
}
});
MotionEvent event= MotionEvent.CREATOR.createFromParcel(null);
switch (event.getAction())
{
case MotionEvent.ACTION_DOWN:
//display click message
}
convertView.onTrackballEvent(event);
return convertView;
}
class ViewHolder {
TextView textLine;
TextView textLine2;
TextView PostedByAndPostedOn;
ImageButton ImgButton;
}
@Override
public Filter getFilter() {
return null;
}
@Override
public long getItemId(int position) {
return 0;
}
@Override
public int getCount() {
return ad_id.length;
}
@Override
public Object getItem(int position) {
return ad_id[position];
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
适配器与“ontracballevent”无关。您要么需要子类化 ListView 要么在您的活动中处理它。
Adapters have nothing to do with "ontracballevent". You either need to subclass ListView or handle it in your activity.