【问题标题】:Android - SimpleCursorAdapter ListView can not clickAndroid - SimpleCursorAdapter ListView 无法点击
【发布时间】:2014-02-28 08:20:33
【问题描述】:

我想将 listview 与 SimpleCursorAdapter 类一起使用。我的问题是我无法单击列表视图。
我的适配器类是....

public class ColorAdapter extends SimpleCursorAdapter {
    private Context context;

    public ColorAdapter(Context context, int layout, Cursor c,
            String[] from, int[] to) {
        super(context, layout, c, from, to);
        this.context = context;
    }

    public int getCount() {
        // TODO Auto-generated method stub
        return MyArrList.size();
    }

    public Object getItem(int position) {
        // TODO Auto-generated method stub
        return position;
    }

    public long getItemId(int position) {
        // TODO Auto-generated method stub
        return position;
    }

    public View getView(int position, View convertView, ViewGroup parent) {
        if (convertView == null) {
            LayoutInflater inflater = (LayoutInflater) context
                    .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            convertView = inflater.inflate(R.layout.event_list, null);
        }

        TextView tname = (TextView) convertView.findViewById(R.id.ename);
        tname.setText(MyArrList.get(position).get("EventName"));

        TextView tdetail = (TextView) convertView
                .findViewById(R.id.edetail);// ใส่ข้อมูลทีละส่วน
        tdetail.setText(MyArrList.get(position).get("EventDetail"));

        return convertView;
    }
}


点击方法是....

elist.setOnItemClickListener(new OnItemClickListener() {
        public void onItemClick(AdapterView<?> parent, View v,
                int position, long id) {
            Intent intent = new Intent(getApplicationContext(),
                    EventsDetail.class);
            String eventName = MyArrList.get(position).get("EventName").toString();

            intent.putExtra("EventName", eventName);
            startActivity(intent);
        }
    });

当我单击 listview 时,什么也没有发生。有人可以帮帮我吗?

【问题讨论】:

    标签: android listview click simpleadapter


    【解决方案1】:

    我几天前遇到了这个问题,问题应该存在于列表行布局中,在您的列表行布局xml根元素中,输入android:descendantFocusability="blocksDescendants",它对我很有效。

    希望对你有帮助!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-04-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多