0

我正在使用gridview,每个正方形中的视图都是相对布局。如果相对布局中有编辑文本或按钮,onitemclicklistener 将不起作用。

适配器没有问题,因为我在没有任何编辑文本或按钮的情况下测试了 onclicklistener 并且它有效。

如何使其与编辑文本和按钮一起使用?

项目布局

    <ImageView
        android:id="@+id/ivcustom1"
        android:layout_width="100dp"
        android:layout_height="100dp"
        android:src="@drawable/selectexcercise" />

    <TextView
        android:id="@+id/tvcustomsets1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_below="@+id/ivcustom1"
        android:textColor="#3498db"
        android:text="Sets:" />

    <TextView
        android:id="@+id/tvcustomreps1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_below="@+id/tvcustomsets1"
        android:textColor="#3498db"
        android:text="Reps:" />

    <EditText
        android:id="@+id/etcustom2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBaseline="@+id/tvcustomreps1"
        android:layout_alignBottom="@+id/tvcustomreps1"
        android:layout_alignRight="@+id/ivcustom1"
        android:background="@android:color/transparent"
        android:hint="Enter Reps"
        android:textColor="#3498db"
        android:inputType="number"
        android:maxLength="6"
        android:textSize="12sp" >
    </EditText>

    <EditText
        android:id="@+id/etcustom1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBaseline="@+id/tvcustomsets1"
        android:layout_alignBottom="@+id/tvcustomsets1"
        android:layout_alignLeft="@+id/etcustom2"
        android:background="@android:color/transparent"
        android:hint="Enter Sets"
        android:textColor="#3498db"
        android:inputType="number"
        android:maxLength="6"
        android:textSize="12sp" />

    <View
        android:layout_width="match_parent"
        android:layout_height="1dp"
        android:layout_alignBottom="@+id/ivcustom1"
        android:layout_alignRight="@+id/etcustom1"
        android:background="#3498db" />

    <Button
        android:id="@+id/button1"
        android:layout_width="match_parent"
        android:layout_height="23dp"
        android:layout_alignLeft="@+id/tvcustomreps1"
        android:layout_alignRight="@+id/etcustom1"
        android:layout_below="@+id/tvcustomreps1"
        android:background="@drawable/stretchesclicked"
        android:text="Note"
        android:textColor="#FFFFFF"
        android:textSize="14sp" />

</RelativeLayout>

以防万一这里是 onitemclicklistener

gridview.setOnItemClickListener(new OnItemClickListener() {
        public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
            System.out.println("The position is" + position);
        }
    });

和适配器

 public class CustomWorkoutAdapter extends BaseAdapter {
    private Context mContext;

    public CustomWorkoutAdapter(Context c) {
        mContext = c;
    }

    public int getCount() {
        return rList.size();
    }

    public Object getItem(int position) {
        return null;
    }

    public long getItemId(int position) {
        return 0;
    }

    // create a new ImageView for each item referenced by the Adapter
    public View getView(final int position, View convertView,
            ViewGroup parent) {

        RelativeLayout RL = rList.get(position);

        return RL;
    }

}
4

2 回答 2

0

在您的 Itemlayout 中,添加以下内容:

 android:descendantFocusability="blocksDescendants"

试试看。

于 2013-11-13T02:38:19.293 回答
0

ListViews 不是为此而设计的。如果您希望某个项目可编辑,则处理 ListView.OnItemClickListener() 事件并有一个对话框弹出窗口允许他们对其进行编辑。

于 2013-11-13T03:53:52.480 回答