的一部分,因为在主题我的应用跳过代码。不要问我为什么要使用线程,它也发生在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