所有按钮都没有显示?这里提到我有71个按钮

时间:2018-03-05 18:36:21

标签: java android xml android-layout

我是android编程的新手。我需要xml文件中的71个按钮。所以我手动为所有71个按钮编写代码。当我运行它从31号码显示的程序。但它会从按钮1显示。

主XML文件正常工作。问题是当我按下第一个按钮= Dhaka Divison时。

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.al_arafahbank.www.aibl_branches.dhaka">

<ScrollView
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:orientation="vertical"
        android:padding="10dp">

        <Button
            android:id="@id/dhaka"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Dhaka Division"
            android:textStyle="bold" />

        <Button
            android:id="@+id/dhk1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Abdullahpur SME Branch, Dhaka "
            android:textStyle="bold" />

        <Button
            android:id="@+id/dhk2"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Amin Bazar Branch, Dhaka "
            android:textStyle="bold" />

        <Button
            android:id="@+id/dhk3"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Ati Bazar Branch, Dhaka "
            android:textStyle="bold" />

        <Button
            android:id="@+id/dhk4"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Azampur Branch, Dhaka "
            android:textStyle="bold" />

        <Button
            android:id="@+id/dhk5"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Banani Branch (AD), Dhaka "
            android:textStyle="bold" />

        <Button
            android:id="@+id/dhk6"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Bandar, SME Branch, narayanganj"
            android:textStyle="bold" />

        <Button
            android:id="@+id/dhk7"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="BASHUNDHARA BRANCH, Dhaka "
            android:textStyle="bold" />

        <Button
            android:id="@+id/dhk8"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Bhagyakul Branch, Munshigonj"
            android:textStyle="bold" />

        <Button
            android:id="@+id/dhk9"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Bhairab Branch, Kishoregonj"
            android:textStyle="bold" />

        <Button
            android:id="@+id/dhk10"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Bhelanagar Branch, ,Narshingdi"
            android:textStyle="bold" />

        <Button
            android:id="@+id/dhk11"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Bormi Branch, Gazipur."
            android:textStyle="bold" />

        <Button
            android:id="@+id/dhk12"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Daxminkhan Branch, Dhaka"
            android:textStyle="bold" />

        <Button
            android:id="@+id/dhk13"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Dhanmondi Branch(AD), Dhaka"
            android:textStyle="bold" />

        <Button
            android:id="@+id/dhk14"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text=" Dilkusha Branch (AD), Dhaka"
            android:textStyle="bold" />

        <Button
            android:id="@+id/dhk15"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Faridpur Branch, Faridpur"
            android:textStyle="bold" />

        <Button
            android:id="@+id/dhk16"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Fulbaria Branch, Gazipur"
            android:textStyle="bold" />

        <Button
            android:id="@+id/dhk17"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Gazipur Branch, Gazipur"
            android:textStyle="bold" />

        <Button
            android:id="@+id/dhk18"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Gulshan Branch(AD), Dhaka"
            android:textStyle="bold" />

        <Button
            android:id="@+id/dhk19"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Hazaribagh Branch, Dhaka"
            android:textStyle="bold" />

        <Button
            android:id="@+id/dhk20"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Head Office Corporate Branch, Dhaka"
            android:textStyle="bold" />

        <Button
            android:id="@+id/dhk21"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Hemayetpur Branch, Dhaka"
            android:textStyle="bold" />

        <Button
            android:id="@+id/dhk22"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Islampur Branch, Dhaka"
            android:textStyle="bold" />

        <Button
            android:id="@+id/dhk23"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Jatrabari Branch, Dhaka"
            android:textStyle="bold" />

        <Button
            android:id="@+id/dhk24"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Joydebpur Chowrasta Branch, Gazipur"
            android:textStyle="bold" />

        <Button
            android:id="@+id/dhk25"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Kaliakoir Branch, Gazipur"
            android:textStyle="bold" />

        <Button
            android:id="@+id/dhk26"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Kaligonj Branch, Dhaka"
            android:textStyle="bold" />

        <Button
            android:id="@+id/dhk27"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Kamrangirchar Branch, Dhaka"
            android:textStyle="bold" />

        <Button
            android:id="@+id/dhk28"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Kapashia Branch, Gazipur"
            android:textStyle="bold" />

        <Button
            android:id="@+id/dhk29"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Kathgora Bazar Branch, Dhaka"
            android:textStyle="bold" />

        <Button
            android:id="@+id/dhk30"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Kawran Bazar Branch, Dhaka"
            android:textStyle="bold" />

        <Button
            android:id="@+id/dhk31"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Kazirhat Branch, Shoriothpur"
            android:textStyle="bold" />

        <Button
            android:id="@+id/dhk32"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Keranigonj Branch, Dhaka"
            android:textStyle="bold" />

        <Button
            android:id="@+id/dhk33"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Khilkhet Branch, Dhaka"
            android:textStyle="bold" />

        <Button
            android:id="@+id/dhk34"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Kolatia SME Branch, Dhaka"
            android:textStyle="bold" />

        <Button
            android:id="@+id/dhk35"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Konapara Branch, Dhaka"
            android:textStyle="bold" />

        <Button
            android:id="@+id/dhk36"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="LOUHAJUNG BRANCH, Monshigonj"
            android:textStyle="bold" />

        <Button
            android:id="@+id/dhk37"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Madhabdi Branch, Narshingdhi"
            android:textStyle="bold" />

        <Button
            android:id="@+id/dhk38"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Manda Branch, Dhaka"
            android:textStyle="bold" />

        <Button
            android:id="@+id/dhk39"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Mirpur Branch, Dhaka"
            android:textStyle="bold" />

        <Button
            android:id="@+id/dhk40"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Mirpur-10 Golchattar Branch, Dhaka"
            android:textStyle="bold" />

        <Button
            android:id="@+id/dhk41"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Mohakhali Branch, Dhaka"
            android:textStyle="bold" />

        <Button
            android:id="@+id/dhk42"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Mohammadpur Krishi Market Branch, Dhaka"
            android:textStyle="bold" />

        <Button
            android:id="@+id/dhk43"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="MOSTAFAPUR BRANCH, Madaripur"
            android:textStyle="bold" />

        <Button
            android:id="@+id/dhk44"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Motijheel Branch (AD), Dhaka"
            android:textStyle="bold" />

        <Button
            android:id="@+id/dhk45"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Motijheel Corporate Branch (AD), Dhaka"
            android:textStyle="bold" />

        <Button
            android:id="@+id/dhk46"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Mouchak Branch, Dhaka"
            android:textStyle="bold" />

        <Button
            android:id="@+id/dhk47"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Moulvi Bazar Branch Dhaka (AD), Dhaka"
            android:textStyle="bold" />

        <Button
            android:id="@+id/dhk48"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Mymensingh Branch, Mymenshingh"
            android:textStyle="bold" />

        <Button
            android:id="@+id/dhk49"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Nandipara Branch, Dhaka"
            android:textStyle="bold" />

        <Button
            android:id="@+id/dhk50"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Narayangonj Branch, Narayangonj"
            android:textStyle="bold" />

        <Button
            android:id="@+id/dhk51"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Natun Bazar Baridhara Branch, Dhaka"
            android:textStyle="bold" />

        <Button
            android:id="@+id/dhk52"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Nawabpur Road Branch (AD), Dhaka"
            android:textStyle="bold" />

        <Button
            android:id="@+id/dhk53"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Nayapur Branch, Narayangonj"
            android:textStyle="bold" />

        <Button
            android:id="@+id/dhk54"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Netrokona Branch, Netrokona"
            android:textStyle="bold" />

        <Button
            android:id="@+id/dhk55"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="New Elephant Road Branch(AD), Dhaka"
            android:textStyle="bold" />

        <Button
            android:id="@+id/dhk56"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="North South Road Branch (AD), Dhaka"
            android:textStyle="bold" />

        <Button
            android:id="@+id/dhk57"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Pagla Branch, Narayangonj"
            android:textStyle="bold" />

        <Button
            android:id="@+id/dhk58"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Pallabi Branch, Dhaka"
            android:textStyle="bold" />

        <Button
            android:id="@+id/dhk59"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text=" Panchdona SME Branch, Narshingdhi"
            android:textStyle="bold" />

        <Button
            android:id="@+id/dhk60"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text=" Panthapath Branch, Dhaka"
            android:textStyle="bold" />

        <Button
            android:id="@+id/dhk61"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Progati Sarani Branch, Dhaka"
            android:textStyle="bold" />

        <Button
            android:id="@+id/dhk62"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Rampal Branch, Munshigonj"
            android:textStyle="bold" />

        <Button
            android:id="@+id/dhk63"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Rampura Branch, Dhaka"
            android:textStyle="bold" />

        <Button
            android:id="@+id/dhk64"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Ruhitpur Branch, Dhaka"
            android:textStyle="bold" />

        <Button
            android:id="@+id/dhk65"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Shyamoli Branch, Dhaka"
            android:textStyle="bold" />

        <Button
            android:id="@+id/dhk66"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Sonargaon Janapath Road Branch, Dhaka"
            android:textStyle="bold" />

        <Button
            android:id="@+id/dhk67"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="South Jatrabari Branch, Dhaka"
            android:textStyle="bold" />

        <Button
            android:id="@+id/dhk68"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="TANGAIL BRANCH, Tangail"
            android:textStyle="bold" />

        <Button
            android:id="@+id/dhk69"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text=" TONGI BRANCH, Gazipur"
            android:textStyle="bold" />

        <Button
            android:id="@+id/dhk70"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Uttara Model Town Branch(AD), Dhaka"
            android:textStyle="bold" />

        <Button
            android:id="@+id/dhk71"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="VIP Road Branch (AD), Dhaka"
            android:textStyle="bold" />
      </LinearLayout>
  </ScrollView>
</LinearLayout>

这是我的MainActivity.java代码

package com.al_arafahbank.www.aibl_branches;

import android.content.Intent;
import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.Button;

public class MainActivity extends AppCompatActivity {

Button barishal1, chittagong, dhaka1, khulna1, rajshahi1, rangpur1, sylhet1;


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


    dhaka1 = (Button) findViewById(R.id.dhaka);
    dhaka1.setOnClickListener(new View.OnClickListener(){

        //  private View v;

        @Override
        public void onClick(View v) {
            Intent i= new Intent(MainActivity.this,dhaka.class);
            startActivity(i);
        }
    });


    barishal1 = (Button) findViewById(R.id.barishal);
    barishal1.setOnClickListener(new View.OnClickListener(){

        //  private View v;

        @Override
        public void onClick(View v) {
            Intent i= new Intent(MainActivity.this,barishal.class);
            startActivity(i);
        }
    });

    chittagong = (Button) findViewById(R.id.chittagong);
    chittagong.setOnClickListener(new View.OnClickListener(){

        //  private View v;

        @Override
        public void onClick(View v) {
            Intent i= new Intent(MainActivity.this,chittagong.class);
            startActivity(i);
        }
    });

    khulna1 = (Button) findViewById(R.id.khulna);
    khulna1.setOnClickListener(new View.OnClickListener(){

        //  private View v;

        @Override
        public void onClick(View v) {
            Intent i= new Intent(MainActivity.this,khulna.class);
            startActivity(i);
        }
    });

    rajshahi1 = (Button) findViewById(R.id.rajshahi);
    rajshahi1.setOnClickListener(new View.OnClickListener(){

        //  private View v;

        @Override
        public void onClick(View v) {
            Intent i= new Intent(MainActivity.this,rajshahi.class);
            startActivity(i);
        }
    });

    sylhet1 = (Button) findViewById(R.id.sylhet);
    sylhet1.setOnClickListener(new View.OnClickListener(){

        //  private View v;

        @Override
        public void onClick(View v) {
            Intent i= new Intent(MainActivity.this,sylhet.class);
            startActivity(i);
        }
    });

    rangpur1 = (Button) findViewById(R.id.rangpur);
    rangpur1.setOnClickListener(new View.OnClickListener(){

        //  private View v;

        @Override
        public void onClick(View v) {
            Intent i= new Intent(MainActivity.this,rangpur.class);
            startActivity(i);
        }
    });

  }
}

当我跑的时候显示这张照片。 [在此输入图像说明] [2] 它显示从30或31数字按钮。但它必须显示第一个按钮“达卡分部”并继续。请帮助。

enter image description here

2 个答案:

答案 0 :(得分:0)

首先,在第一个按钮中添加+属性id,因为它已丢失。

答案 1 :(得分:0)

哇。您在.xml文件上努力工作。但是,如果您这样做,那么它就有99%的机会出错。您错过了 + 个ID。 我认为您需要使用回收视图或动态创建按钮。like this