ListActivity not behaving

Put your problem here if it does not fit any of the other categories.

ListActivity not behaving

Postby ksly » Wed May 20, 2009 3:30 am

Hello experts.

I have a problem with this code.

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2. public class AddNum extends ListActivity {
  3.  
  4.  
  5.  
  6.         public String Num;
  7.  
  8.         Button btnAdd;
  9.  
  10.         ListView LV;
  11.  
  12.  
  13.  
  14.         @Override
  15.  
  16.         protected void onActivityResult(int requestCode, int resultCode, Intent data) {        
  17.  
  18.                 try{
  19.  
  20.                 ListItems.add("test") ;
  21.  
  22.                 ListItemsAdapter.notifyDataSetChanged();
  23.  
  24.        
  25.  
  26.                 }catch(Exception ex){
  27.  
  28.                         Log.d("ERR",ex.getMessage());
  29.  
  30.                 }
  31.  
  32.                 super.onActivityResult(requestCode, resultCode, data);
  33.  
  34.         }
  35.  
  36.  
  37.  
  38.         ArrayList<String>ListItems= new ArrayList<String>();
  39.  
  40.         ArrayAdapter<String> ListItemsAdapter;
  41.  
  42.         @Override
  43.  
  44.         public void finish() {
  45.  
  46.                 super.finish();
  47.  
  48.         }
  49.  
  50.  
  51.  
  52.         @Override
  53.  
  54.         protected void onCreate(Bundle savedInstanceState) {
  55.  
  56.                
  57.  
  58.                 super.onCreate(savedInstanceState);
  59.  
  60.                 setContentView(R.layout.addcontacts);
  61.  
  62.                
  63.  
  64.                 btnAdd = (Button)findViewById(R.id.btnAdd);
  65.  
  66.                  
  67.  
  68.                 ListItemsAdapter = new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,
  69.  
  70.                                 ListItems);    
  71.  
  72.                 setListAdapter(ListItemsAdapter);
  73.  
  74.                 btnAdd.setOnClickListener( new OnClickListener(){
  75.  
  76.                         @Override
  77.  
  78.                         public void onClick(View v) {
  79.  
  80.                                 Intent i = new Intent(AddNum.this,Dialer.class);
  81.  
  82.                                 AddNum.this.startActivityForResult(i, 1);
  83.  
  84.                                
  85.  
  86.                         }
  87.  
  88.                 });
  89.  
  90.                
  91.  
  92.         }
  93.  
  94. }
  95.  
  96.  
Parsed in 0.036 seconds, using GeSHi 1.0.8.4


The thing it works fine except , when onActivityResult is called the listItems ArrayList never has any items in it, it is allways zero in size, even after adding items to it, it never changes. I hope someone can shed some light on this isssue
ksly
Freshman
Freshman
 
Posts: 3
Joined: Sat Apr 11, 2009 2:17 am

Top

Postby arams » Mon May 25, 2009 12:26 pm

u want to set like this:
LV=new ListView(this);
LV.setAdapter();
arams
Experienced Developer
Experienced Developer
 
Posts: 89
Joined: Fri May 08, 2009 7:45 am

Top

Return to Other Coding-Problems

Who is online

Users browsing this forum: Exabot [Bot] and 12 guests