如何使用列表项调用alertbox? [英] How to call alertbox using list item ?

查看:85
本文介绍了如何使用列表项调用alertbox?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在每次检查中都设置了一个复选框,它调用了一个函数



 call.setOnClickListener( new  View.OnClickListener(){
@ Override
public void onClick(查看视图){
checkbox =(CheckBox)findViewById(R.id.checkBox1);
ListView mainListView = mDrawerList ;
checkbox =(CheckBox)mainListView.getChildAt( 0 );
checkbox =(CheckBox)mainListView.getChildAt( 1 );
checkbox =(CheckBox)mainListView.getChildAt( 2 );
checkbox =(CheckBox) mainListView.getChildAt( 3 );
for INT x = 0 ; x< mainListView.getChildCount(); x ++){

if (checkbox.isChecked()){
getMain();

}

else if (checkbox1。 isChecked()){
second();

}
else if (checkbox2.isChecked()) {
third();

}
else if (checkbox3.isChecked()) {
forth();

} else {
getMain();

}
}
}
});





这是我的DrawlerList.xml



< pre lang =xml> < CheckBox
android:id = @ + id / checkBox1
android :layout_width = wrap_content
android:layout_height = wrap_content
android:text =
android:layout_centerVertical = true
android:layout_alignParentLeft = true
android:layout_alignParentStart = true / >

< TextView
android:id = @ + id / title
android:layout_width = wrap_content
android:layout_height = match_parent
android:layout_toRightOf = @ id / checkBox1
android:minHeight = ?android:attr / listPreferredItemHeightSmall
< span class =code-attribute> android:textAppearance = ?android:attr / textAppearanceListItemSmall
< span class =code-attribute> android:textColor = @ color / list_item_title
android:重力 = center_vertical
android:paddingRight = 40dp / >





在string.xml中我设置了我的项目名称



 <! -    导航抽屉菜单项   - >   
< string-array name = nav_drawer_items >
< item > 主页 < / item >
< item > 第二个 < / item >
< item > 第三个< / item >
< item > Forth < / item >
< / string-array >





但是当我只点击一个复选框但显示所有功能提示框时



我尝试了什么:



当我尝试只调用一个函数时



call.setOnClickListener(new View.OnClickListener(){

@Override

public void onClick(View view){

getMain(); //现在只有一个警报框

}

});

解决方案

这只是一个重新发布从每个功能获取警报对话框 [ ^ ],我已经告诉过你了您的代码出了什么问题。你上面发布的内容比你开始时更糟糕。请回到原文,再看看我告诉你的内容。


I have make a checkbox in each check it call a function

call.setOnClickListener(new View.OnClickListener() {
           @Override
           public void onClick(View view) {
               checkbox = (CheckBox) findViewById(R.id.checkBox1);
               ListView mainListView = mDrawerList;
               checkbox = (CheckBox) mainListView.getChildAt(0);
               checkbox = (CheckBox) mainListView.getChildAt(1);
               checkbox = (CheckBox) mainListView.getChildAt(2);
               checkbox = (CheckBox) mainListView.getChildAt(3);
               for (int x = 0; x < mainListView.getChildCount(); x++) {

                   if (checkbox.isChecked()) {
                       getMain();

                   }

                   else if (checkbox1.isChecked()) {
                       second();

                   }
                   else if (checkbox2.isChecked()) {
                       third();

                   }
                   else if (checkbox3.isChecked()) {
                       forth();

                   } else {
                       getMain();

                   }
               }
           }
       });



This is my DrawlerList.xml

<CheckBox
    android:id="@+id/checkBox1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text=""
    android:layout_centerVertical="true"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true" />

<TextView
    android:id="@+id/title"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:layout_toRightOf="@id/checkBox1"
    android:minHeight="?android:attr/listPreferredItemHeightSmall"
    android:textAppearance="?android:attr/textAppearanceListItemSmall"
    android:textColor="@color/list_item_title"
    android:gravity="center_vertical"
    android:paddingRight="40dp"/>



And in string.xml i set my items name

<!-- Nav Drawer Menu Items -->
   <string-array name="nav_drawer_items">
       <item>Home</item>
       <item>Second</item>
       <item>Third</item>
       <item>Forth</item>
   </string-array>



But when i clicking only one checkbox but it displaying all function alertbox also

What I have tried:

When i try to call only one function

call.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
getMain(); // Now only one alert box is there
}
});

解决方案

This is just a repost of Alertdialog box getting from every function[^], where I already told you what was wrong with your code. And what you have posted above is worse than what you started with. Please go back to the original and look again at what I told you.


这篇关于如何使用列表项调用alertbox?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆