开发者

try to do a public method

开发者 https://www.devze.com 2023-01-14 20:39 出处:网络
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 :

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'开发者_StackOverflowt 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();


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, int position, AdapterView parent){

        TextView str1 = new TextView(this);
        str1.setText(parent.getItemAtPosition(position).toString());
        String title = str1.getText().toString();

        TextView str = new TextView(this);
        str.setText(ID);
        String text = str.getText().toString();

        new AlertDialog.Builder(this).setTitle(title).setMessage(text).setNeutralButton("close", new DialogInterface.OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int which) {
                // TODO Auto-generated method stub

            }
        }).show();

        }

that's it -_-', i made some progress.

0

精彩评论

暂无评论...
验证码 换一张
取 消