当我单击SOUTHPARK时,它将打开KYLE
我想让KYLE可点击并在KYLE中写点东西,我该怎么做?

如果相关,我可以复制粘贴清单

我差不多要在这里写些东西,这样我才能发布

public class MainActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    String[] tvShows = {"southPark","naruto","simpsons","americandad"};

    String[] southPark = {"Kyle"};

    String[] naruto = {"naruto"};

    String[] simpsons = {"bart"};

    String[] americandad = {"Stan"};

    ListAdapter adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1,tvShows);

    final ListView theListView = (ListView) findViewById(R.id.theListView1);
    theListView.setAdapter(adapter);

    theListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {

            int itemPosition = position;
            String value = (String) theListView.getItemAtPosition(position);

            switch (value){
                case "southPark":
                    Intent southparkScreen = new Intent(MainActivity.this, SouthPark.class);
                    MainActivity.this.startActivity(southparkScreen);
                    break;
                case "naruto":
                    Intent narutoscreen = new Intent(MainActivity.this, Naruto.class);
                    MainActivity.this.startActivity(narutoscreen);
                    break;
                case "simpsons":
                    Intent simpsonsScreen = new Intent(MainActivity.this, Simpsons.class);
                    MainActivity.this.startActivity(simpsonsScreen);
                    break;

                case "americandad":
                    Intent americandadscreen = new Intent(MainActivity.this, AmericanDad.class);
                    MainActivity.this.startActivity(americandadscreen);
                    break;


            }

        }


    });

}


南园

public class SouthPark extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.second_layout);


    String[] southPark = {"Kyle"};


    ListAdapter adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, southPark);

    final ListView theListView = (ListView) findViewById(R.id.theListView2);
    theListView.setAdapter(adapter);
}


activity_main.xml

    <?xml version="1.0" encoding="utf-8"?>
      <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

   <ListView
       android:layout_width="wrap_content"
       android:layout_height="wrap_content"
       android:id="@+id/theListView1">
   </ListView>

</RelativeLayout>


second_layout.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="match_parent"
    android:layout_height="match_parent">

    <ListView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/theListView2"></ListView>



</LinearLayout>

最佳答案

您可以在列表视图上设置OnItemClickListener:

listView.setOnItemClickListener(new OnItemClickListener() {

public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
    Object o = prestListView.getItemAtPosition(position);
    //...
}


});

07-26 05:09