的一部分,因爲在主題我的應用跳過代碼。不要問我爲什麼要使用線程,它也發生在try/catch上。經過幾個小時的測試,我發現它與.xml中的android.support.v4.widget.DrawerLayout有關。有誰知道這個解決方案?我的android應用跳過代碼
public class MainActivity extends Activity {
private String[] drawerListViewItems = new String[]{"Test","Also test","Guess what","Another test"};
private ListView drawerListView;
String a="one";
int i=0;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// get list items from strings.xml
// drawerListViewItems = getResources().getStringArray(R.array.items);
TextView lol = (TextView) findViewById (R.id.textView1);
lol.setText("#YOLO");
new Thread (new Runnable() { // This whole thread is skipped for no reason.
public void run() {
a="SWAG";
i++;
}
}).start();
lol.setText(a+" "+i);
// get ListView defined in activity_main.xml
drawerListView = (ListView) findViewById(R.id.left_drawer);
// Set the adapter for the list view
drawerListView.setAdapter(new ArrayAdapter<String>(this,
R.layout.drawer_listview_item, drawerListViewItems));
}
}
當然輸出爲 「一個0」 在我的應用程序。我希望它是「SWAG 1」,我需要它在線程中。另外,不要問我爲什麼用串那樣:)呵呵,有.xml文件:
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- The main content view -->
<RelativeLayout
android:id="@+id/content_frame"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView android:text="TextView"
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<!-- The navigation drawer -->
<ListView android:id="@+id/left_drawer"
android:layout_width="240dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:choiceMode="singleChoice"
android:divider="#666"
android:dividerHeight="1dp"
android:background="#333"
android:paddingLeft="15sp"
android:paddingRight="15sp"
/>
謝謝,它完美的作品。 – Darknez 2014-09-24 15:39:32