Android 单击自定义listview项Edittext时打开自定义对话框
单击自定义列表视图项时,我想打开一个自定义对话框() 我已经试过了,但是无法打开对话框。以下是代码详细信息:Android 单击自定义listview项Edittext时打开自定义对话框,android,Android,单击自定义列表视图项时,我想打开一个自定义对话框() 我已经试过了,但是无法打开对话框。以下是代码详细信息: @Override protected void onListItemClick(ListView l, View v, int position, long id) { // TODO Auto-generated method stub super.onListItemClick(l, v, position, id); Dialog dialog = ne
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
// TODO Auto-generated method stub
super.onListItemClick(l, v, position, id);
Dialog dialog = new Dialog(this);
dialog.setContentView(R.layout.input_dialog);
dialog.setTitle("What about Today!");
**//initialize custom dialog items.**
EditText mood = (EditText) dialog.findViewById(R.id.editTextyourMode);
Button btnSaveButton = (Button) dialog
.findViewById(R.id.btnSaveMyMoods);
Button btnClear = (Button) dialog
.findViewById(R.id.btnClear);
dialog.show();
}
下面是自定义数组适配器getView(…)方法
最后,我想在单击列表视图项编辑文本时打开此对话框。
有人帮我吗?对不起,我没有看到您正在使用自定义适配器,请在适配器中执行此操作
rowView.setClickable(true);
rowView.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View paramView)
{
//if you want you can use the "position" value to get the desired row items.
}
});
抱歉,我没有看到您正在使用CustomAdapter,请在适配器中执行此操作
rowView.setClickable(true);
rowView.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View paramView)
{
//if you want you can use the "position" value to get the desired row items.
}
});
尝试:
尝试:
在编辑文本上设置onclick侦听器,如果它没有弹出任何对话框,请尝试设置edittext的设置android:focusable=“false”也就是说,如果您已经在编辑文本上放置了一个侦听器,但仍然没有发生任何事情,请在编辑文本上设置onclick侦听器,如果它没有弹出任何对话框,请尝试设置edittext的设置安卓:focusable=“false”也就是说,如果您已经在编辑文本上放置了一个侦听器,但仍然没有发生任何事情我在适配器中的getView(…)中打开了从这些内容键入的对话框,并且还可以显示在所选的listview项EditText上
rowView.setClickable(true);
rowView.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
dialog = new Dialog(context);
dialog.setContentView(R.layout.input_dialog);
dialog.setTitle("What about Today!");
final EditText txtMode = (EditText) dialog
.findViewById(R.id.editTextyourMode);
Button btnSave = (Button) dialog
.findViewById(R.id.btnSaveMyMoods);
btnSave.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
String data = txtMode.getText().toString();
product_quantity.setText(data);
dialog.dismiss();
Log.d("data", data);
}
});
dialog.show();
}
});
然后屏幕看起来就是这样。
现在面临一个问题。我的列表视图只有10个项目。当我滚动列表视图时,项目文本消失,这是看不见的
感谢大家分享知识。**我在适配器中的getView(…)中打开这些对话框,并可以在所选的listview项上显示EditText
rowView.setClickable(true);
rowView.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
dialog = new Dialog(context);
dialog.setContentView(R.layout.input_dialog);
dialog.setTitle("What about Today!");
final EditText txtMode = (EditText) dialog
.findViewById(R.id.editTextyourMode);
Button btnSave = (Button) dialog
.findViewById(R.id.btnSaveMyMoods);
btnSave.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
String data = txtMode.getText().toString();
product_quantity.setText(data);
dialog.dismiss();
Log.d("data", data);
}
});
dialog.show();
}
});
然后屏幕看起来就是这样。
现在面临一个问题。我的列表视图只有10个项目。当我滚动列表视图时,项目文本消失,这是看不见的
感谢大家分享知识。**在Adpter中编写此代码
EditText product_quantity = (EditText) convertView
.findViewById(R.id.editTextQuantity);
product_quantity.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Dialog dialog = new Dialog(context);
dialog.setContentView(R.layout.input_dialog);
dialog.setTitle("What about Today!");
//initialize custom dialog items.**
EditText mood = (EditText) dialog.findViewById(R.id.editTextyourMode);
Button btnSaveButton = (Button) dialog
.findViewById(R.id.btnSaveMyMoods);
Button btnClear = (Button) dialog
.findViewById(R.id.btnClear);
dialog.show();
}
});
在Adpter中编写此代码
EditText product_quantity = (EditText) convertView
.findViewById(R.id.editTextQuantity);
product_quantity.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Dialog dialog = new Dialog(context);
dialog.setContentView(R.layout.input_dialog);
dialog.setTitle("What about Today!");
//initialize custom dialog items.**
EditText mood = (EditText) dialog.findViewById(R.id.editTextyourMode);
Button btnSaveButton = (Button) dialog
.findViewById(R.id.btnSaveMyMoods);
Button btnClear = (Button) dialog
.findViewById(R.id.btnClear);
dialog.show();
}
});
您应该在getView()方法中将OnClickListener设置为“product\u quantity”,并在那里完成您的工作。@Carnal:谢谢您的互动。我尝试了您的方法。我的目标是在自定义对话框编辑文本中将列表视图编辑框中的文本设置为“product\u quantity”。您应该在getView()中将OnClickListener设置为“product\u quantity”方法并在那里完成您的工作。@Carnal:谢谢您的互动。我尝试了您的方法。我的目标是从自定义对话框编辑文本中设置列表视图编辑框中的文本。谢谢,它工作得很好。但现在我想从对话框edittext输入中将文本设置为edittext。提前谢谢。谢谢你。。。玩得开心!!:谢谢,很好用。但现在我想从对话框edittext输入中将文本设置为edittext。提前谢谢。谢谢你。。。享受编码的乐趣!!android:focusable=“false”仅用于选择列表视图项。thanksandroid:focusable=“false”仅用于选择列表视图项。感谢此问题的回收列表视图等关闭对话框,请将编辑框文本存储在ArrayList或任何其他数据中。还请使用视图持有者编写代码。上下文从何而来?这是回收列表视图的问题,请关闭对话框。请将编辑框文本存储在ArrayList或任何其他数据中。还请使用视图持有者编写代码。上下文从何而来?