gpt4 book ai didi

android - 单击自定义 ListView 项 Edittext 时打开自定义对话框

转载 作者:行者123 更新时间:2023-11-29 16:11:58 25 4
gpt4 key购买 nike

我想在单击我的自定义 ListView 项时打开自定义 Dialog()。

到目前为止我已经尝试过,但无法打开对话框。这是代码详细信息:

@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(...) 方法。

@Override
public View getView(int position, View convertView, ViewGroup parent) {

LayoutInflater inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

View rowView = inflater.inflate(R.layout.sell_info_list, parent, false);


TextView product_id = (TextView) rowView.findViewById(R.id.product_id);//
product_id.setText(products.get(position).getProduct_id());

EditText product_quantity = (EditText) rowView
.findViewById(R.id.editTextQuantity);

return rowView;
}

最后,我想在单击 ListView 项编辑文本时打开此对话框。有人帮帮我吗?

最佳答案

尝试:

// Click event for single list row
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
super.onListItemClick(l, v, position, id);
EditText edit = (EditText) (findViewById(R.id.editText));
if (edit != null) {
edit.setOnClickListener(new View.OnClickListener() {

@Override
public void onClick(View v) {
Toast.makeText(MainActivity.this, "CLICKED",
Toast.LENGTH_LONG).show();
}
});
} else {
Toast.makeText(MainActivity.this, "EditText not found",
Toast.LENGTH_LONG).show();
}
}
});

关于android - 单击自定义 ListView 项 Edittext 时打开自定义对话框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12400920/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com