Android 按钮点击不工作

Android 按钮点击不工作,android,button,Android,Button,我的活动中有多个按钮,但问题是当setOnClickListener时,有些按钮被单击,有些按钮未被单击 这是我的项目的重要组成部分,我非常渴望这样做。但是我没有成功。所以请帮帮我。我已经检查了多个解决方案从其他网站,但没有工作 这是myactivity代码部分 public class Home extends ActionBarActivity { String htmlText = "<html><body style=\"text-align:justify

我的活动中有多个按钮,但问题是当
setOnClickListener
时,有些按钮被单击,有些按钮未被单击

这是我的项目的重要组成部分,我非常渴望这样做。但是我没有成功。所以请帮帮我。我已经检查了多个解决方案从其他网站,但没有工作

这是myactivity代码部分

public class Home extends  ActionBarActivity {

    String htmlText = "<html><body style=\"text-align:justify\"> %s </body></Html>";

    //HOME SECTION
    TextView txt1,txt2,txt3,txt4,txt5,txt6;
    WebView webview1,webview2,webview3;
    WebSettings websetting;

    Button btnhowtouse,btnteacher, btn_addlocation, btn_student_parents;


    Dialog dialog;
    TextView txt_howtouse,txtdialog1,txtdialog2,txtdialog3,txtdialog4,txtdialog5,txtdialog6,txtdialog7,txtdialog8,txtdialog9,txtdialog10,txtdialog11,
    txtdialog12,txtdialog13,txtdialog14,txtdialog15,txtdialog16,txtdialog17,txtdialog18,txtdialog19,txtdialog20,txtdialog21,txtdialog22,txtdialog23;

    ImageView imgcross; 

    Toolbar toolbar;

    int groupid;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_usecoop);


        toolbar=(Toolbar)findViewById(R.id.toolbar);

        try {

            setSupportActionBar(toolbar);
            getSupportActionBar().setDisplayHomeAsUpEnabled(true);
            getSupportActionBar().setDisplayShowHomeEnabled(true);


        } catch (Exception e) {
        }


        btnhowtouse=(Button)findViewById(R.id.btn_howtouse);
        btnteacher=(Button)findViewById(R.id.btn_teacherlocator);
        btn_addlocation=(Button)findViewById(R.id.btn_addlocation); 
        btn_student_parents=(Button)findViewById(R.id.btn_student_parents); 




        Intent it=getIntent();
        groupid=it.getIntExtra("Groupid", 0);

        Toast.makeText(Home.this, "Goupid"+groupid, Toast.LENGTH_LONG).show();


        if(groupid==4)
        {

            btnteacher.setVisibility(View.VISIBLE);
            btn_student_parents.setVisibility(View.GONE);
            btn_addlocation.setVisibility(View.GONE);
        }


        else if(groupid==3)
        {
            btn_student_parents.setVisibility(View.VISIBLE);
            btnteacher.setVisibility(View.GONE);
            btn_addlocation.setVisibility(View.GONE);


        }

        else 
        {



            btn_addlocation.setVisibility(View.VISIBLE);
            btnteacher.setVisibility(View.GONE);
            btn_student_parents.setVisibility(View.GONE);

        }



        btn_student_parents.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {

                Toast.makeText(Home.this, "Clicked Student parents", Toast.LENGTH_LONG).show();
                Intent it=new Intent(Home.this,TeacherLocator.class);
                startActivity(it);

            }
        });






            btnteacher.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                Intent it=new Intent(Home.this,TeacherLocator.class);
                startActivity(it);

            }
        });






        btn_addlocation.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {


                Toast.makeText(Home.this, "Currently you are not able to add location", Toast.LENGTH_LONG).show();

            }
        });



        txt1=(TextView)findViewById(R.id.txt_home1);
        txt2=(TextView)findViewById(R.id.txt_home2);
        txt3=(TextView)findViewById(R.id.txt_home3);
        txt4=(TextView)findViewById(R.id.txt_home4);
        txt5=(TextView)findViewById(R.id.txt_home5);
        txt6=(TextView)findViewById(R.id.txt_home6);

        webview1=(WebView)findViewById(R.id.web_view1);
        webview2=(WebView)findViewById(R.id.web_view2);
        webview3=(WebView)findViewById(R.id.web_view3);

        txt2.setText("Text1");
        txt4.setText("Text2");
        txt6.setText("Text3");

        websetting=webview1.getSettings();
        websetting=webview2.getSettings();
        websetting=webview3.getSettings();





        webview1.loadData(String.format(htmlText, txt2.getText()), "text/html", "utf-8");
        webview2.loadData(String.format(htmlText, txt4.getText()), "text/html", "utf-8");
        webview3.loadData(String.format(htmlText, txt6.getText()), "text/html", "utf-8");







        btnhowtouse.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                dialog=new Dialog(Home.this);
                dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); 
                dialog.setContentView(R.layout.dilogusecoop);
                dialog.setCancelable(true);
                dialog.show();          

                imgcross=(ImageView)dialog.findViewById(R.id.img_corss);
                imgcross.setOnClickListener(new OnClickListener() {

                    @Override
                    public void onClick(View v) {
                        dialog.dismiss();
                    }
                });

                txt_howtouse=(TextView)dialog.findViewById(R.id.txt_howtouse);
                txtdialog1=(TextView)dialog.findViewById(R.id.txt_1);
                txtdialog2=(TextView)dialog.findViewById(R.id.txt_2);
                txtdialog3=(TextView)dialog.findViewById(R.id.txt_3);
                txtdialog4=(TextView)dialog.findViewById(R.id.txt_4);
                txtdialog5=(TextView)dialog.findViewById(R.id.txt_5);
                txtdialog6=(TextView)dialog.findViewById(R.id.txt_6);
                txtdialog7=(TextView)dialog.findViewById(R.id.txt_7);
                txtdialog8=(TextView)dialog.findViewById(R.id.txt_8);
                txtdialog9=(TextView)dialog.findViewById(R.id.txt_9);
                txtdialog10=(TextView)dialog.findViewById(R.id.txt_10);
                txtdialog11=(TextView)dialog.findViewById(R.id.txt_11);
                txtdialog12=(TextView)dialog.findViewById(R.id.txt_12);
                txtdialog13=(TextView)dialog.findViewById(R.id.txt_13);
                txtdialog14=(TextView)dialog.findViewById(R.id.txt_14);
                txtdialog15=(TextView)dialog.findViewById(R.id.txt_15);
                txtdialog16=(TextView)dialog.findViewById(R.id.txt_16);
                txtdialog17=(TextView)dialog.findViewById(R.id.txt_17);
                txtdialog18=(TextView)dialog.findViewById(R.id.txt_18);
                txtdialog19=(TextView)dialog.findViewById(R.id.txt_19);
                txtdialog20=(TextView)dialog.findViewById(R.id.txt_20);
                txtdialog21=(TextView)dialog.findViewById(R.id.txt_21);
                txtdialog22=(TextView)dialog.findViewById(R.id.txt_22);
                txtdialog23=(TextView)dialog.findViewById(R.id.txt_23); 
            }
        });





    }


}

This is my layout please help me find out this problem.





<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#ffffff"


   >

    <include
            android:id="@+id/toolbar"
            layout="@layout/toolbar" />


 <Button
        android:id="@+id/btn_howtouse"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_marginBottom="5dp"
        android:layout_marginLeft="5dp"
        android:layout_marginRight="5dp"
        android:background="#4385F5"
        android:textColor="#ffffff"
        android:text="How To Locator" />

    <Button
        android:id="@+id/btn_teacherlocator"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_marginLeft="5dp"
        android:layout_marginRight="5dp"
        android:layout_marginBottom="5dp"
        android:background="#4385F5"
        android:textColor="#ffffff"
        android:text="Teacher Locator"
        android:layout_above="@+id/btn_howtouse" />



    <Button
        android:id="@+id/btn_student_parents"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_marginLeft="5dp"
        android:layout_marginRight="5dp"
        android:layout_marginBottom="5dp"
        android:background="#4385F5"
        android:textColor="#ffffff"
        android:text="Parents/Students Locator"
        android:visibility="gone"

        android:layout_above="@+id/btn_howtouse" />



     <Button
        android:id="@+id/btn_addlocation"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_marginLeft="5dp"
        android:layout_marginRight="5dp"
        android:layout_marginBottom="5dp"
        android:background="#4385F5"
        android:textColor="#ffffff"
        android:text="Add Location"
        android:visibility="gone"

        android:layout_above="@+id/btn_howtouse" />


    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_marginBottom="5dp"
        android:layout_below="@+id/toolbar"
        android:layout_above="@+id/btn_teacherlocator" >

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="#ffffff" >

            <TextView
                android:id="@+id/txt_home1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginLeft="5dp"
                android:layout_marginTop="5dp"
                android:text="Home"
                android:textSize="25sp"
                android:textStyle="bold" />

          <WebView
                android:id="@+id/web_view1"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_below="@+id/txt_home1"
                android:layout_marginLeft="5dp"
                android:layout_marginRight="5dp"
                android:layout_marginTop="5dp" />

            <TextView
                android:id="@+id/txt_home2"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                  android:layout_below="@+id/txt_home1"
              />

            <TextView
                android:id="@+id/txt_home3"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_below="@+id/web_view1"
                android:layout_marginLeft="5dp"
                android:layout_marginTop="5dp"
                android:textColor="#000000"
                android:textStyle="bold"
                android:textSize="20sp"
                android:text="What is  Education?" />

          <WebView
                android:id="@+id/web_view2"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_below="@+id/txt_home3"
                android:layout_marginLeft="5dp"
                android:layout_marginRight="5dp"
                android:layout_marginTop="5dp" /> 

            <TextView
                android:id="@+id/txt_home4"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"

                 android:layout_below="@+id/txt_home3"
             />

            <TextView
                android:id="@+id/txt_home5"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_below="@+id/web_view2"
                android:layout_marginLeft="5dp"
                android:layout_marginTop="5dp"
                android:textColor="#000000"
                android:textStyle="bold"
                android:textSize="20sp"
                android:text="What are the benefits of  Education?" />

            <WebView
                android:id="@+id/web_view3"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_below="@+id/txt_home5"
                android:layout_marginLeft="5dp"
                android:layout_marginRight="5dp"
                android:layout_marginTop="5dp" /> 

            <TextView
                android:id="@+id/txt_home6"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_below="@+id/txt_home5" />
        </RelativeLayout>
    </ScrollView>


</RelativeLayout> 
公共类主页扩展了ActionBarActivity{
字符串htmlText=“%s”;
//主页
TextView txt1、txt2、txt3、txt4、txt5、txt6;
WebView webview1、webview2、webview3;
腹板设置腹板设置;
按钮btnhowtouse、Btnetacher、btn\u addlocation、btn\u student\u parents;
对话;
TextView txt_howtouse、txtdialog1、txtdialog2、txtdialog3、txtdialog4、txtdialog5、txtdialog6、txtdialog7、txtdialog8、txtdialog9、txtdialog10、txtdialog11、,
txtdialog12、txtdialog13、txtdialog14、txtdialog15、txtdialog16、txtdialog17、txtdialog18、txtdialog19、txtdialog20、txtdialog21、txtdialog22、txtdialog23;
ImageView imgcross;
工具栏;
int-groupid;
@凌驾
创建时受保护的void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_usecop);
toolbar=(toolbar)findviewbyd(R.id.toolbar);
试一试{
设置支持操作栏(工具栏);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setDisplayShowHomeEnabled(true);
}捕获(例外e){
}
btnhowtouse=(按钮)findViewById(R.id.btn\u howtouse);
btnteacher=(按钮)findViewById(R.id.btn\u teacherlocator);
btn_addlocation=(按钮)findViewById(R.id.btn_addlocation);
btn_学生家长=(按钮)findViewById(R.id.btn_学生家长);
Intent it=getIntent();
groupid=it.getIntExtra(“groupid”,0);
Toast.makeText(Home.this,“Goupid”+groupid,Toast.LENGTH_LONG).show();
if(groupid==4)
{
btnteacher.setVisibility(View.VISIBLE);
btn_student_parents.setVisibility(View.GONE);
btn_addlocation.setVisibility(View.GONE);
}
else if(groupid==3)
{
btn_student_parents.setVisibility(View.VISIBLE);
btnteacher.setVisibility(View.GONE);
btn_addlocation.setVisibility(View.GONE);
}
其他的
{
btn_addlocation.setVisibility(View.VISIBLE);
btnteacher.setVisibility(View.GONE);
btn_student_parents.setVisibility(View.GONE);
}
btn_student_parents.setOnClickListener(新的OnClickListener(){
@凌驾
公共void onClick(视图v){
Toast.makeText(Home.this,“单击学生家长”,Toast.LENGTH_LONG.show();
Intent it=新Intent(Home.this,TeacherLocator.class);
星触觉(it);
}
});
setOnClickListener(新的OnClickListener(){
@凌驾
公共void onClick(视图v){
Intent it=新Intent(Home.this,TeacherLocator.class);
星触觉(it);
}
});
btn_addlocation.setOnClickListener(新的OnClickListener(){
@凌驾
公共void onClick(视图v){
Toast.makeText(Home.this,“当前无法添加位置”,Toast.LENGTH_LONG.show();
}
});
txt1=(TextView)findViewById(R.id.txt_home1);
txt2=(TextView)findViewById(R.id.txt_home2);
txt3=(TextView)findViewById(R.id.txt_home3);
txt4=(TextView)findViewById(R.id.txt_home4);
txt5=(TextView)findViewById(R.id.txt_home5);
txt6=(TextView)findViewById(R.id.txt_home6);
webview1=(WebView)findViewById(R.id.web\u view1);
webview2=(WebView)findViewById(R.id.web\u view2);
webview3=(WebView)findViewById(R.id.web\u view3);
txt2.setText(“Text1”);
txt4.setText(“Text2”);
txt6.setText(“Text3”);
websetting=webview1.getSettings();
websetting=webview2.getSettings();
websetting=webview3.getSettings();
loadData(String.format(htmlText,txt2.getText()),“text/html”,“utf-8”);
loadData(String.format(htmlText,txt4.getText()),“text/html”,“utf-8”);
loadData(String.format(htmlText,txt6.getText()),“text/html”,“utf-8”);
setOnClickListener(新的OnClickListener()文件){
@凌驾
公共void onClick(视图v){
dialog=新建对话框(Home.this);
对话框.requestWindowFeature(窗口.FEATURE\u无\u标题);
setContentView(R.layout.dilogusecop);
对话框。可设置可取消(true);
dialog.show();
imgcross=(ImageView)dialog.findViewById(R.id.img_corss);
setOnClickListener(新的OnClickListener(){
@凌驾
公共void onClick(视图v){
dialog.dismise();
}
});
txt_howtouse=(TextView)dialog.findviewbyd(R.id.txt_howtouse);
txtdialog1=(TextView)dialog.findViewById(R.id.txt_1);
txtdialog2=(TextView)dialog.findViewById(R.id.txt_2);
txtdialog3=(TextView)dialog.findViewById(R.id.txt_3);
txtdialog4=(TextView)dialog.findViewById(R.id.txt_4);
txtdialog5=(TextView)dialog.findViewById(R.id.txt_5);
txtdialog6=(TextView)dialog.findViewById(R.id.txt_6);
txtdialog7=(TextView)dialog.findViewById(R.id.txt_7);
txtdialog8=(TextView)dialog.findViewById(R.id.txt_8);
txtdialog9=(TextView)dialog.findViewById(R.id.txt_9);
txtdialog10=(TextView)dialog.findViewById(R.id.txt_10);
txtdialog11=(TextView)dialog.findViewById(R.id.txt_11);
android:onClick="Button_Click"
public void Button_Click(View v) {
    // Add your Code
}
 <Button
    android:id="@+id/btn_student_parents"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_marginLeft="5dp"
    android:layout_marginRight="5dp"
    android:layout_marginBottom="5dp"
    android:background="#4385F5"
    android:textColor="#ffffff"
    android:text="Parents/Students Locator"
    android:onClick="Button_Click"
    android:layout_above="@+id/btn_howtouse" />