有谁知道如何以编程方式设置按钮的文本?Android以编程方式设置按钮文本
事情是我没有从主布局(setContentView)调用这个我打电话给一个视图,这是一个asynctask后膨胀 继承人我试过,但这是给第二行空指针异常
Button mButton=(Button)findViewById(R.id.contact);
mButton.setText("number");
我的继承人布局,其中我打电话按钮
<Button
android:id="@+id/contact"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/address"
android:layout_toLeftOf="@+id/badge"
android:background="@drawable/ic_btn_call"
android:textSize="10dp"
android:textStyle="bold"
android:textColor="@color/white"/>
这里我认为我正在充气
ClubInfo = LayoutInflater.from(getBaseContext()).inflate(R.layout.clubinfocell,
null);
TextView TeamNameText = (TextView) ClubInfo.findViewById(R.id.TeamName);
TeamNameText.setText(teamName);
TextView AddressText = (TextView) ClubInfo.findViewById(R.id.address);
AddressText.setText(address1);
Button mButton=(Button)ClubInfo.findViewById(R.id.contact);
mButton.setText(telephone);
你可以发表你的全onCreate方法这里? – Cata
请提供完整的java代码文件。 –
它给NPE,因为mButton在第一行为空。那是因为findViewById没有找到你提供给它的R.id.contact。 –