从一个ListView移动到另一个ListView

时间:2015-06-21 07:41:39

标签: android listview android-activity android-listview listactivity

我是android开发的新手,这里创建列表项是我的两个类的代码。我正试图从菜单移动到另一个活动(预付),也实现了列表视图。问题是它无法转移到预付费活动。菜单类中还缺少我的标题,如何在菜单类上显示标题栏?

菜单类

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();
    }

}

}

预付费课程

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();
    }
}

}

1 个答案:

答案 0 :(得分:1)

MD已经提供了将一个列表活动移动到第二个列表活动的ans。只需添加点(。),如

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

对于标题问题,请点击This Tutorial,这可能会对您有所帮助。本教程修复了所有活动的页眉和页脚。