尝试做一个公共方法
我想创建一个方法来打开一个弹出窗口,当我点击它时,标题和文本将是自动的,如下所示:
public void Display(String test){
new AlertDialog.Builder(this).setTitle(getTitle()).setMessage(test).setNeutralButton("close", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
}
}).show();
}
但测试是一个字符串,并且设置消息不接受字符串,并且它将来自资源XML,如 Strings.xml。所以我不知道如何做到这一点。 而“getTitle()”我认为它不起作用。我的取名方法就是这个。
TextView str = new TextView(this);
str.setText(parent.getItemAtPosition(position).toString());
String title = str.getText().toString();
i want to create a method to open a popup when i click on it and the title and the text would be automatic, something like this :
public void Display(String test){
new AlertDialog.Builder(this).setTitle(getTitle()).setMessage(test).setNeutralButton("close", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
}
}).show();
}
but test is a String and set Message doesn't accept Strings, and it would come from a resource XML, like Strings.xml. So i don't know ho to do this.
And the 'getTitle()' i don't think it could work. My method to take the title is this one.
TextView str = new TextView(this);
str.setText(parent.getItemAtPosition(position).toString());
String title = str.getText().toString();
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
setMessage 确实接受字符串。查看文档:
setMessage(CharSequence message)
您可以传入一个字符串。您是否尝试编译代码?
setMessage does accept strings. Look at the documentation:
setMessage(CharSequence message)
You can pass a String in. Did you try to compile your code?
public void Display(int ID, intposition, AdapterViewparent){
就是这样-_-',我取得了一些进展。
public void Display(int ID, int position, AdapterView parent){
that's it -_-', i made some progress.