Search code examples
androidlistviewandroid-activityandroid-listviewlistactivity

Moving from one ListView to another ListView


I am new in android development and create list item here is my code of both classes. I am trying to move from Menu to another activity(Prepaid) which also implemented list view. Problem is it can not move to Prepaid activity. Also my Header is missing from menu class, how to show header bar on menu class?

Menu Class

public class Menu extends ListActivity {

String classes[] = {"Prepaid" , "Postpaid"};

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setListAdapter(new ArrayAdapter<String>(Menu.this, android.R.layout.simple_list_item_1, classes));
}

@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
    super.onListItemClick(l, v, position, id);
    String whichItemClicked = classes[position];

    try
    {
        Class ourClass = Class.forName("adnan.com.ufone" + whichItemClicked);
        Intent ourIntent = new Intent(Menu.this, ourClass);
        startActivity(ourIntent);
    }
    catch (ClassNotFoundException e)
    {
        e.printStackTrace();
    }

}

}

Prepaid Class

public class Prepaid extends ListActivity {

String prepaidServices[] = {"UAdbanced" , "Packages", "Internet"};

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setListAdapter(new ArrayAdapter<String>(Prepaid.this , android.R.layout.simple_list_item_1, prepaidServices ));

}

@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
    super.onListItemClick(l, v, position, id);
    String ItemClicket = prepaidServices[position];

    try{
        Class myClass = Class.forName("adnan.com.ufone" + ItemClicket);
        Intent myIntent = new Intent(Prepaid.this, myClass);
        startActivity(myIntent);

    }
    catch (ClassNotFoundException e){
        e.printStackTrace();
    }
}

}


Solution

  • MD already provided the ans for moving one list activity to second list activity. Just need to add dot(.) like

    Class ourClass = Class.forName("adnan.com.ufone." + whichItemClicked);
    

    For header problem follow This Tutorial this may help you. This tutorial fix the header and footer for all activities.