我的OnItemclicklistener无法正常工作:我在点击监听器上调用了Itemclicklistener,但它无法正常工作

时间:2017-03-25 10:33:03

标签: java android onitemclicklistener

我正在尝试在图像点击监听器上显示弹出窗口,并且从该弹出窗口我想要获取值,但我没有从弹出窗口中获取值。 我在点击监听器上调用了Itemclicklistener,但它没有工作。

这是我的代码:

public void onClick(View view)
{
    if(view.getId()==R.id.imgv_search)
    {
        LayoutInflater inflator = (LayoutInflater)Home.this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        View show_menu_popup = inflator.inflate(R.layout.popup_list, null);
        ListView listv_problems = (ListView) show_menu_popup.findViewById(R.id.listv_problems);
        AdapterCity city = new AdapterCity(Home.this,al_cityid,al_cityname);
        listv_problems.setAdapter(city);
        Dialog dialog_menus = new Dialog(Home.this);
        dialog_menus.setTitle("Select city : ");
        dialog_menus.setContentView(show_menu_popup);
        dialog_menus.show();
        listv_problems.setOnItemClickListener(this);
        //Toast.makeText(Home.this,"City is changed : "+edt_city_name.getText(),Toast.LENGTH_SHORT).show();
    }
}

这是我的OnItemclickListener:

public void onItemClick(AdapterView<?> adapterView, View view, int position, long l)
{
    if(adapterView.getId()== R.id.listv_problems)
    {
        //TextView cityid= (TextView)adapterView.findViewById(R.id.cityid);
        //String city_id=  cityid.getText().toString();
        Toast.makeText(Home.this,"You click popup",Toast.LENGTH_LONG);
    }
}

1 个答案:

答案 0 :(得分:0)

你可以使用......

document.getElementsByClassName('should_be_replaced')[0].parentNode.inn‌​erHTML = str

或者您可以在public void onItemClick(AdapterView<?> adapterView, View view, int position, long l) { al_citynames.get(position); //this will give you the value of city Toast.makeText(Home.this,"You click popup",Toast.LENGTH_LONG); }

中使用view.getitembyposition()