Question

List works properly. After clicking wants to display the own dialogue, but is error:

android.view.WindowManager$BadTokenException: Unable to add window -- token null is not for an application

My code:

public class View_List_Of_Reports extends Activity{
    Context context;
    @Override
    protected void onCreate(Bundle savedInstanceState) {

        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        setContentView(R.layout.view_list_of_reports);

        String[] nazwyRaportow = {"Podsumowanie dnia", "Sprzedaz wg marka/model", "Sprzedaz wg marka", "Sprzedaz wg rodzaj paliwa", "Sprzedaz wg typ nadwozia"};
        String[] szczegolyRaportow = {"Podsumowanie sprzedazy w obecnymm dniu - Lista sprzedazy ","Sczegoly raportu_b ","Sczegoly raportu_c ","Sczegoly raportu_d ","Sczegoly raportu_e "};

        context = getApplicationContext();
        MobileArrayAdapter adapter = new MobileArrayAdapter(context , nazwyRaportow, szczegolyRaportow);

        ListView lista = (ListView) findViewById(R.id.listViewViewListOfReports);
        lista.setAdapter(adapter);
        lista.setOnItemClickListener(onListClick);

    }// end create

private class MobileArrayAdapter extends ArrayAdapter<String> {
        private final Context context;
        private final String[] values;
        private final String[] values2;

        public MobileArrayAdapter(Context context, String[] values, String[] values2) {
            super(context, R.layout.row_report, values);
            this.context = context;
            this.values = values;
            this.values2 = values2;
        }

        @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.row_report, parent, false);
            TextView textView = (TextView) rowView.findViewById(R.id.tvRRNazwaRaportu);
            TextView textView2 = (TextView) rowView.findViewById(R.id.tvRRSczegolyRaportu);

            textView.setText(values[position]);
            textView2.setText(values2[position]);

            return rowView;
        }
    }   

private AdapterView.OnItemClickListener onListClick=new AdapterView.OnItemClickListener() {
    public void onItemClick(AdapterView<?> parent, View view, int position, long id)
    {

                    Dialog dialog1 = new Dialog(context);
                    dialog1.setContentView(R.layout.view_dialog1);
                    dialog1.show();

    }

};
}// end activity

Please help

Was it helpful?

Solution

For a Dialog you have to use Activity's instance not application context.

Try this

private AdapterView.OnItemClickListener onListClick=new AdapterView.OnItemClickListener() {
    public void onItemClick(AdapterView<?> parent, View view, int position, long id)
    {

                    Dialog dialog1 = new Dialog(View_List_Of_Reports.this);
                    dialog1.setContentView(R.layout.view_dialog1);
                    dialog1.show();

    }

};
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top