ボタンのテキストをプログラムで設定する方法を知っている人はいますか?Androidプログラムでボタンのテキストを設定する
私はメインレイアウト(setContentView)からこれを呼び出すことはありません。私はasynctaskの後で膨らんだビューでそれを呼び出しています heres何を試しましたが、これは2行目でnullポインタ例外を与えています
Button mButton=(Button)findViewById(R.id.contact);
mButton.setText("number");
私は
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);
を膨らませるんだ、ここでボタン
<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"/>
私の見解を呼び出していますHERESに私のレイアウト
あなたがフルのonCreateメソッドを投稿することができますここに? – Cata
完全なJavaコードファイルをご提供ください。 –
最初の行でmButtonがnullであるため、NPEを返します。これは、findViewByIdが、あなたが提供したR.id.contactを見つけられなかったためです。 –