Androidアプリを作成するためにグループで作業しています。現在、いくつかの選択可能なもの(文字列配列から適応)を表示するListViewで構成されるアクティビティを作成する必要があります-最終的にListViewは、作成しているオブジェクトの配列を取ります.また、その時点でサーバーで使用できるオブジェクトに応じて、このオブジェクトの配列が変更されます (したがって、ListView のエントリが変更されます)。しかし今のところ、文字列の配列で動作させる必要があります。
だから、これが私の活動のxmlとJavaのメインです。
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="center">
<ListView
android:id="@+id/gamesListView"
android:layout_width="match_parent"
android:layout_height="320dp"
android:entries="@+id/gamesList"
>
</ListView>
<Button
android:layout_width="fill_parent"
android:layout_height="45dp"
android:text="Create"
android:id="@+id/bCreate"
/>
<Button
android:layout_width="fill_parent"
android:layout_height="45dp"
android:text="Refresh"
android:id="@+id/bRefresh"
/>
</LinearLayout>
package com.youcanthide.android.gamespage;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ListView;
public class MainActivity extends Activity {
Button create, refresh; //browse
String gamesList[] = {"game1", "game2", "game3"};
//Game [] games; **********//the array of available games to populate the SlideView
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
create = (Button) findViewById(R.id.bCreate);
refresh = (Button) findViewById(R.id.bRefresh);
ListView games = (ListView) findViewById(R.id.gamesListView);
//Will have to remake adapter for Game objects
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, gamesList);
games.setAdapter(adapter);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
私はAPIと簡単なチュートリアルに従おうとしましたが、なぜそれが壊れているのかまだわかりません. Eclipse にエラー メッセージはありませんが、アクティビティのエミュレーターを実行すると、「残念ながら (プロジェクト名) が停止しました」というメッセージが表示されます。どんな助けでも大歓迎です!