views:

45

answers:

2

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();
+1  A: 

setMessage does accept strings. Look at the documentation:

setMessage(CharSequence message)

You can pass a String in. Did you try to compile your code?

EboMike
excuse me that's not what i meant, i wanted to put and id in it, but the id refers to a strings...
Tsunaze
Can you explain what you're talking about? You want to put an ID in it? What is "it"? What ID? What "id" refers to a strings?!
EboMike
It was something like R.strings.texttodisplay but i found out =)
Tsunaze
A: 

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.

Tsunaze