これがコードです。そのかなり自明です。私が抱えている唯一の問題は、int レベルの値を保持することです。そのたびに失われます。値を保持する必要があり、それは機能します。これはスナップショットです。レベルごとに同じ数のアイテムまで拡張できる必要があります。
XML コード:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
tools:context=".MainActivity" >
<ListView
android:id="@+id/listView1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true" >
</ListView>
</RelativeLayout>
Java コード:
package com.example.kjkjsdkjdsjkdfs;
import android.app.ListActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;
public class MainActivity extends ListActivity {
String categoryselected = "main";
public int level = 0;
@SuppressWarnings("null")
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
String[] array;
Intent received = getIntent();
// Setup as main ListView
if (received == null || !received.hasExtra("array")) {
array = new String[] { "1", "2", "3" };
}
// Setup as sub ListView
else {
array = received.getStringArrayExtra("array");
}
if(received != null || !received.hasExtra("level")) {
level = received.getIntExtra("level", 0);
}
setListAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, array));
}
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
level = level + 1;
Intent starting = new Intent(MainActivity.this, MainActivity.class);
switch (level) {
case 1:
switch (position) {
case 0:
starting.putExtra("array", new String[] { "1a", "1b", "1c" });
starting.putExtra("level", level);
break;
case 1:
starting.putExtra("array", new String[] { "2a", "2b", "2c" });
starting.putExtra("level", level);
break;
case 2:
starting.putExtra("array", new String[] { "3a", "3b", "3c" });
starting.putExtra("level", level);
break;
}
break;
case 2:
switch (position) {
case 0:
starting.putExtra("array", new String[] { "1aa", "1ab" });
starting.putExtra("level", level);
break;
}
break;
case 3:
switch (position) {
case 0:
starting.putExtra("array", new String[] { "1aaa", "1aab" });
starting.putExtra("level", level);
break;
}
break;
}
startActivity(starting);
}
@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;
}
}