1. Introducing Channels - a new way to chat with other Android users!
    Dismiss Notice

How to get listview click? And back button?


Last Updated:

  1. AlexMason

    AlexMason Well-Known Member This Topic's Starter

    Joined:
    Aug 28, 2010
    Messages:
    118
    Likes Received:
    14
    I have my files all set up to make my list view and when i click on a item from list view i want it to make an output but everything i found online and tryed makes and Force Close here is my files.
    Main Class:
    Code (Text):
    1. package com.alexmason.mkw;
    2.  
    3. import android.app.Activity;
    4. import android.os.Bundle;
    5. import android.view.View;
    6. import android.widget.AdapterView;
    7. import android.widget.AdapterView.OnItemClickListener;
    8. import android.widget.Button;
    9. import android.widget.ListView;
    10. import android.widget.Toast;
    11.  
    12. public class Main extends Activity {
    13.     /** Called when the activity is first created. */
    14.     @Override
    15.     public void onCreate(Bundle savedInstanceState) {
    16.         super.onCreate(savedInstanceState);
    17.         setContentView(R.layout.main);
    18.         final Button btnMarioChar = (Button) findViewById(R.id.BtnMarioChar);
    19.         final Button btnMarioBike = (Button) findViewById(R.id.BtnMarioBike);
    20.         final Button btnMarioKart = (Button) findViewById(R.id.BtnMarioKart);
    21.         final ListView lvMarioChar = (ListView) findViewById(R.id.MarioCharListView);
    22.         final ListView lvMarioBike = (ListView) findViewById(R.id.MarioBikeListView);
    23.         final ListView lvMarioKart = (ListView) findViewById(R.id.MarioKartListView);
    24.         btnMarioChar.setOnClickListener(new View.OnClickListener() {
    25.             public void onClick(View v) {
    26.                 setContentView(R.layout.mariochar);
    27.             }
    28.         });
    29.         btnMarioKart.setOnClickListener(new View.OnClickListener() {
    30.             public void onClick(View v) {
    31.                 setContentView(R.layout.mariokart);
    32.             }
    33.         });
    34.         btnMarioBike.setOnClickListener(new View.OnClickListener() {
    35.             public void onClick(View v) {
    36.                 setContentView(R.layout.mariobike);
    37.             }
    38.         });
    39.     }
    40.    
    41. }
    XML's
    Code (Text):
    1. <?xml version="1.0" encoding="utf-8"?>
    2. <LinearLayout
    3.   xmlns:android="http://schemas.android.com/apk/res/android"
    4.   android:layout_width="fill_parent"
    5.   android:layout_height="fill_parent">
    6. <ListView android:id="@+id/MarioCharListView" android:layout_width="fill_parent" android:layout_height="wrap_content" android:entries="@array/mariocharlist"></ListView>
    7. </LinearLayout>
    8.  
    Code (Text):
    1. <?xml version="1.0" encoding="utf-8"?>
    2. <LinearLayout
    3.   xmlns:android="http://schemas.android.com/apk/res/android"
    4.   android:layout_width="fill_parent"
    5.   android:layout_height="wrap_content">
    6. <ListView android:id="@+id/MarioKartListView" android:layout_width="fill_parent" android:layout_height="wrap_content" android:entries="@array/mariokartlist"></ListView>
    7. </LinearLayout>
    8.  
     

    Advertisement

Share This Page

Loading...