android onclick fragment,android fragment setOnClickListener

该问题涉及在Android Fragment中为特殊键盘上的按钮设置点击事件监听器。开发者已经尝试了多种方法,包括在onCreateView和onActivityCreated中设置监听器,但未能成功检测到点击事件。建议检查XML布局文件中EditText的clickable属性是否设为true,并确保特殊键盘布局已包含在当前ContentView中。同时,推荐使用一个公共的OnClickListener并为所有按钮绑定。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

问题

I use fragment and when i click on an editext an layou is shown whith an special keyboard, (many buttons clickable), but i can't find he correct way to detect the click on buttons

here's the onCreateView code:

public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState)

{

View view = inflater.inflate(R.layout.fragment_rsslist_overview,container, false);

try {

setKeys();

} catch (Exception e) {

Log.w(getClass().getName(), e.toString());

}

//

return view;

}

Here's the setKeys code: (i've try many things on mBSpace button)

public void setKeys() {

mWindowWidth = getActivity().getWindowManager().getDefaultDisplay().getWidth(); // getting

// window

// height

// getting ids from xml files

mB[0] = (Button) getActivity().findViewById(R.id.xA);

mB[1] = (Button) getActivity().findViewById(R.id.xB);

mB[2] = (Button) getActivity().findViewById(R.id.xC);

mB[3] = (Button) getActivity().findViewById(R.id.xD);

mB[4] = (Button) getActivity().findViewById(R.id.xE);

mB[5] = (Button) getActivity().findViewById(R.id.xF);

mB[6] = (Button) getActivity().findViewById(R.id.xG);

mB[7] = (Button) getActivity().findViewById(R.id.xH);

mB[8] = (Button) getActivity().findViewById(R.id.xI);

mB[9] = (Button) getActivity().findViewById(R.id.xJ);

mB[10] = (Button) getActivity().findViewById(R.id.xK);

mB[11] = (Button) getActivity().findViewById(R.id.xL);

mB[12] = (Button) getActivity().findViewById(R.id.xM);

mB[13] = (Button) getActivity().findViewById(R.id.xN);

mB[14] = (Button) getActivity().findViewById(R.id.xO);

mB[15] = (Button) getActivity().findViewById(R.id.xP);

mB[16] = (Button) getActivity().findViewById(R.id.xQ);

mB[17] = (Button) getActivity().findViewById(R.id.xR);

mB[18] = (Button) getActivity().findViewById(R.id.xS);

mB[19] = (Button) getActivity().findViewById(R.id.xT);

mB[20] = (Button) getActivity().findViewById(R.id.xU);

mB[21] = (Button) getActivity().findViewById(R.id.xV);

mB[22] = (Button) getActivity().findViewById(R.id.xW);

mB[23] = (Button) getActivity().findViewById(R.id.xX);

mB[24] = (Button) getActivity().findViewById(R.id.xY);

mB[25] = (Button) getActivity().findViewById(R.id.xZ);

mB[26] = (Button) getActivity().findViewById(R.id.xS1);

mB[27] = (Button) getActivity().findViewById(R.id.xS2);

mB[28] = (Button) getActivity().findViewById(R.id.xS3);

mB[29] = (Button) getActivity().findViewById(R.id.xS4);

mB[30] = (Button) getActivity().findViewById(R.id.xS5);

mB[31] = (Button) getActivity().findViewById(R.id.xS6);

mBSpace = (Button) getActivity().findViewById(R.id.xSpace);

mBdone = (Button) getActivity().findViewById(R.id.xDone);

mBChange = (Button) getActivity().findViewById(R.id.xChange);

mBack = (Button) getActivity().findViewById(R.id.xBack);

mNum = (Button) getActivity().findViewById(R.id.xNum);

// for (int i = 0; i < mB.length; i++)

mBSpace.setOnClickListener( this);

/*

mBSpace.setOnClickListener( new View.OnClickListener() {

@Override

public void onClick(View v) {

// TODO Auto-generated method stub

edittext_onClick(v );

}

});

*/

/*

mB[i].setOnClickListener( this);

mBSpace.setOnClickListener( this);

mBdone.setOnClickListener( this);

mBack.setOnClickListener( this);

mBChange.setOnClickListener( this);

mNum.setOnClickListener( this);

// mNum.setOnClickListener( this);

*/

}

Does somebody known he correct syntax do to this?

I've try call setkey() into :

public void onActivityCreated (Bundle savedInstanceState){

setKeys();

super.onActivityCreated(savedInstanceState);

}

I've no error but no click detection too...

Thx in advance...

回答1:

Did you try android:clickable="true" in the xml elements for EditText?

回答2:

Ensure that the special keyboard layout is part of the present contentView. If it is not and you are inflating it into the current view then when you are getting references to the buttons you should use

buttonA = inflatedLayout.findViewById(R.id.button);

Also create a common onClickListener and bind all the buttons to it

OnClickListener buttonClickListener = new OnClickListener() {

@Override

public void onClick(View v) {

edititext.setText(v.getTag().toString());

// or whatever logic you are using

}

}

来源:https://stackoverflow.com/questions/14976958/android-fragment-setonclicklistener

### PyAutoCAD 文档与用户手册 对于希望深入了解 `PyAutoCAD` 的用户而言,《PyAutoCAD手册 中文版》是一份不可或缺的学习资料[^1]。这份手册不仅涵盖了库的安装指南,还提供了详细的 API 使用说明,帮助读者掌握通过 Python 脚本操作 AutoCAD 图形对象的方法。 #### 安装 PyAutoCAD手册中描述了多种操作系统下 PyAutoCAD 的安装过程,确保不同环境中的开发人员均能顺利配置开发工具链。 #### 基础功能介绍 书中列举了一系列基础教程案例,包括但不限于绘制直线、圆形以及其他几何形状的操作实例。这些例子有助于新手快速上手并理解核心概念。 #### 高级特性探索 除了入门级别的内容外,该书也深入探讨了一些高级主题,比如批量处理绘图文件、自定义命令集的设计思路等,旨在满足有经验用户的进一步需求。 #### 自动化脚本编写 针对那些希望通过编程实现重复性任务自动化的工程师们,《PyAutoCAD手册 中文版》给出了详尽的工作流构建技巧,使得复杂的 CAD 操作变得简单易行。 ```python from pyautocad import Autocad, APoint acad = Autocad(create_if_not_exists=True) p1 = APoint(0, 0) p2 = APoint(50, 25) line = acad.model.AddLine(p1, p2) print(f"Line created from {line.StartPoint} to {line.EndPoint}") ``` 上述代码片段展示了如何利用 PyAutoCAD 创建一条连接两个指定点的新线段,并打印其起点和终点坐标信息。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值