我正在创建一个列表菜单,每次调用我创建它的类时都需要更改。但一旦创建,它仍然是相同的。我尝试使用adapter.clear()但它也不起作用。有人可以在下面的代码中找到编辑。
public class Menu extends ListActivity {
ArrayAdapter<String> adapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
/* for( int i = 0; i< j ; i++) {
classes[i] = Http.sarr[i];
ref[i] = Http.name[i];
}*/
super.onCreate(savedInstanceState);
adapter = new ArrayAdapter<String>(Menu.this, android.R.layout.simple_list_item_1, Http.sarr);
setListAdapter(adapter);
}
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
// TODO Auto-generated method stub
super.onListItemClick(l, v, position, id);
String cheese = Http.name[position];
String link = "http://www.codeforces.com/problemset/problem/";
link = link.concat(cheese);
Intent ourIntent = new Intent("android.intent.action.VIEW", Uri.parse(link));
startActivity(ourIntent);
}
@Override
protected void onPause() {
// TODO Auto-generated method stub
super.onPause();
//finish();
adapter.clear();
adapter.notifyDataSetChanged();
Class ourClass = null;
try {
ourClass = Class.forName("com.example.avinash.myapplication.Mainapp");
Intent ourIntent = new Intent(Menu.this, ourClass);
startActivity(ourIntent);
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
}
}