0
我是android開發中的新手,創建列表項是這兩個類的代碼。我試圖從菜單移動到另一個活動(預付),這也實現了列表視圖。問題是它不能移動到預付費活動。另外我的標題是從菜單類中缺少的,如何在菜單類上顯示標題欄?從一個ListView移動到另一個ListView
菜單類
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();
}
}
}
嘗試'Class ourClass = Class.forName(「adnan.com.ufone。」+ whichItemClicked);'你只需要'add。(dot)' –
讓我檢查@MD –
它的工作原理謝謝你爲什麼不給我是一個適當的答案,以便我接受你的答案?還請告訴我爲什麼我的標題在這兩項活動中都失蹤了? –