怎么获取并鍭lertDialog中EditText的输入值
1个回答
2015-01-25 · 知道合伙人数码行家
huanglenzhi
知道合伙人数码行家
向TA提问 私信TA
知道合伙人数码行家
采纳数:117538
获赞数:517193
长期从事计算机组装,维护,网络组建及管理。对计算机硬件、操作系统安装、典型网络设备具有详细认知。
向TA提问 私信TA
关注
展开全部
如何获取并保存AlertDialog中EditText的输入值?
初学android,被这个小问题卡了一晚上了,dialog可以创建,在EditText中输入后用gettext().tostring()方法得不到值,求解答。。。代码段如下:
final AlertDialog.Builder builder = new AlertDialog.Builder(this);
bn.setOnClickListener(new View.OnClickListener()
{
//@Override
public void onClick(View source)
{
builder.setIcon(R.drawable.tools);
builder.setTitle("XXXX");
RelativeLayout numaddForm = (RelativeLayout)getLayoutInflater()
.inflate( R.layout.numadd, null);
builder.setView(numaddForm);
//final String s_num_temp;
builder.setPositiveButton("确定", new OnClickListener()
{
//@Override
public void onClick(DialogInterface dialog, int which)
{
EditText edit_num = (EditText)view.findViewById(R.id.Edit_t);
String s_num_temp = edit_num.getText().toString().trim();
System.out.println(s_num_temp);
if(isPhoneNumberValid(s_num_temp))
{
s_num=s_num_temp;
}
else
{
Toast num_r_toast=Toast.makeText(MainActivity.this, "XXXXX", Toast.LENGTH_LONG);
num_r_toast.show();
}
}
});
builder.setNegativeButton("取消"
, new OnClickListener()
{
//@Override
public void onClick(DialogInterface dialog, int which)
{
//取消。
}
});
builder.create().show();
}
});
[解决办法]
将
RelativeLayout numaddForm = (RelativeLayout)getLayoutInflater()
.inflate( R.layout.numadd, null);
改为
final RelativeLayout numaddForm = (RelativeLayout)getLayoutInflater()
.inflate( R.layout.numadd, null);
然后将
EditText edit_num = (EditText)view.findViewById(R.id.Edit_t);
改为
EditText edit_num = (EditText) numaddForm.findViewById(R.id.Edit_t);
本文来自:读书人网
初学android,被这个小问题卡了一晚上了,dialog可以创建,在EditText中输入后用gettext().tostring()方法得不到值,求解答。。。代码段如下:
final AlertDialog.Builder builder = new AlertDialog.Builder(this);
bn.setOnClickListener(new View.OnClickListener()
{
//@Override
public void onClick(View source)
{
builder.setIcon(R.drawable.tools);
builder.setTitle("XXXX");
RelativeLayout numaddForm = (RelativeLayout)getLayoutInflater()
.inflate( R.layout.numadd, null);
builder.setView(numaddForm);
//final String s_num_temp;
builder.setPositiveButton("确定", new OnClickListener()
{
//@Override
public void onClick(DialogInterface dialog, int which)
{
EditText edit_num = (EditText)view.findViewById(R.id.Edit_t);
String s_num_temp = edit_num.getText().toString().trim();
System.out.println(s_num_temp);
if(isPhoneNumberValid(s_num_temp))
{
s_num=s_num_temp;
}
else
{
Toast num_r_toast=Toast.makeText(MainActivity.this, "XXXXX", Toast.LENGTH_LONG);
num_r_toast.show();
}
}
});
builder.setNegativeButton("取消"
, new OnClickListener()
{
//@Override
public void onClick(DialogInterface dialog, int which)
{
//取消。
}
});
builder.create().show();
}
});
[解决办法]
将
RelativeLayout numaddForm = (RelativeLayout)getLayoutInflater()
.inflate( R.layout.numadd, null);
改为
final RelativeLayout numaddForm = (RelativeLayout)getLayoutInflater()
.inflate( R.layout.numadd, null);
然后将
EditText edit_num = (EditText)view.findViewById(R.id.Edit_t);
改为
EditText edit_num = (EditText) numaddForm.findViewById(R.id.Edit_t);
本文来自:读书人网
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询