0

我迷路了,所以我可以就如何将列表项链接到单独的活动提供一些帮助吗?我有它来解释我正在尝试做的不同物种。它展示了诸如矮人、人类之类的东西,所有有趣的东西。提前致谢。

 package com.apw.games.rpg.medieval;

 import java.util.ArrayList;
import java.util.Arrays;
import android.app.Activity;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.ListView;

public class Species extends Activity {

  private ListView mainListView ;
  private ArrayAdapter<String> listAdapter ;

  /** Called when the activity is first created. */
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.species);

    // Find the ListView resource. 
    mainListView = (ListView) findViewById( R.id.mainListView );

    // Create and populate a List of planet names.
    String[] planets = new String[] { "Human", "Dwarf", "Earth-Born", "Elf",
                                  "Sky Spirit", "Water Spritit", "Death Spirit", "War Spirit"};  
    ArrayList<String> planetList = new ArrayList<String>();
    planetList.addAll( Arrays.asList(planets) );

    // Create ArrayAdapter using the planet list.
    listAdapter = new ArrayAdapter<String>(this, R.layout.simplerow, planetList);

    // Add more planets. If you passed a String[] instead of a List<String> 
    // into the ArrayAdapter constructor, you must not add more items. 
    // Otherwise an exception will occur.
    listAdapter.add( "Troll- Coming Soon" );
    listAdapter.add( "Giant- Coming Soon" );
    listAdapter.add( "God- Coming Soon" );
    listAdapter.add( "Monster- Coming Soon" );

    // Set the ArrayAdapter as the ListView's adapter.
    mainListView.setAdapter( listAdapter );      
  }
}
4

1 回答 1

1

调用setOnItemClickListener()您的ListView, 然后startActivity()从该onItemClick()侦听器的方法调用。

ListActivity但是Activity,更多时候,您会发现开发人员onListItemClick()在他们的ListActivity. 见:https ://github.com/commonsguy/cw-omnibus/tree/master/Selection/List

于 2012-09-25T23:26:14.133 回答