ListView に文字列配列の値を入力しようとしています。確認したとおり、文字列配列に値があります。以前の検索で見たものから、正しいコードを使用しています。Android エミュレーターを使用してアプリを実行していますが、新しいエミュレーターの作成、プロジェクトのクリーンアップ、および Eclipse の再起動を試みました。しかし、アプリを起動してもリストにデータがありません。
Android 4.2 を実行している Galaxy Nexus エミュレーターを使用しています。
MainActivity.java:
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ListView redditView = (ListView) findViewById(R.id.redditView);
String[] redditList = readRedditFeed();
ArrayAdapter<String> adapter = new ArrayAdapter<String>(
this, android.R.layout.simple_list_item_1, redditList);
redditView.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.activity_main, menu);
return true;
}
public String[] readRedditFeed()
{
return output;
}
}
activity_main.xml:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" >
<ListView
android:id="@+id/redditView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true" >
</ListView>
</RelativeLayout>