0
我想要一組按鈕,並且按鈕上的焦點應該定期更改,首先我想用2個按鈕來嘗試。這是我的main.xml文件。Android自動對焦更改
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<Button
android:id="@+id/number_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="0.72"
android:focusable="true"
android:gravity="center"
android:text="@string/number"
android:textSize="10pt" android:clickable="true"
android:focusableInTouchMode="true"/>
<Button
android:text="@string/contact"
android:textSize="10pt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/contact_button"
android:layout_weight="1" android:layout_gravity="center"
android:focusable="true" android:gravity="center"
android:focusableInTouchMode="true"/>
</LinearLayout>
在源代碼中我已經使用FOCUS_LEFT,RIGHT及其他所有選項,但我得到一個運行時異常。方向以線性設置爲垂直layout.Please幫我理清這個問題,如果有人知道如何定時器選項設置,以及張貼在這裏
這裏是代碼
package com.example.helloandroid;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
public class HelloandroidActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Object o=null;
// o.toString();
// TextView tv = new TextView(this);
// tv.setText("Hello Andriod");
setContentView(R.layout.main);
Button mybtn= (Button)findViewById(R.id.number_button);
mybtn.requestFocus();
try
{
Button mybtn2= (Button)mybtn.focusSearch(View.FOCUS_DOWN);
mybtn2.requestFocus();
}
catch(Exception e)
{
Log.e("focus change","focus failed",e);
}
}
}
什麼RuntimeException?你可以在這裏放一個StackTrace嗎? – 2012-02-09 10:20:59
男孩請儘快回答我的問題,這將是巨大的幫助,因爲它是我的項目所需... – 2012-02-09 10:33:39
@Marek sebera:它是NULL指針異常 – 2012-02-09 10:35:17