FAISAL
FAISAL

Reputation: 459

Intent is not working on click event

Hy experts. i am new to android, i am trying to generate an intent to go on next activity, i am using listview, when i click on list item, it should go to that class which item item is clicked. here is my code.

package com.example.data_server_assi;

import android.app.ListActivity; import android.content.Intent; import android.os.Bundle; import android.view.View; import android.widget.ArrayAdapter; import android.widget.ListView; import android.widget.Toast;

public class Menu extends ListActivity{

String[] menu = {"AddInfo","DataBaseInfo"};

@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setListAdapter(new ArrayAdapter<String>(Menu.this, android.R.layout.simple_list_item_1, menu));
}
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
    // TODO Auto-generated method stub
    super.onListItemClick(l, v, position, id);
    try {

        Toast.makeText(Menu.this, "Test" ,Toast.LENGTH_SHORT).show();
        Class menuItem = Class.forName("com.example.data_server_assi."+menu[position]);

        Intent menuIntent = new Intent(Menu.this,menuItem);

    } catch (ClassNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}

}`

Upvotes: 0

Views: 72

Answers (2)

Anand Prakash
Anand Prakash

Reputation: 401

You have missed starting your activity by-

startActivity(YOUR_INTENT_NAME);

Upvotes: 0

Pratik Dasa
Pratik Dasa

Reputation: 7439

Put below code, You have missed one line of code:

Intent menuIntent = new Intent(Menu.this,menuItem);
 startActivity(menuIntent);

OR

startActivity(new Intent(menu.this,menuItem));

Upvotes: 1

Related Questions