0

I have a listview in my application. It works fine but when the number of elements
increases then on scrolling down and selecting any view,it shows the force close.
Why so? The code segment is given as:

 lv1 = (ListView) findViewById(R.id.listView);
     lv1.setAdapter(new ArrayAdapter<String>(this,R.layout.list_item,surveyName));
    // lv1 = getListView();
     lv1.setOnItemClickListener(new OnItemClickListener() {
           public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
             long arg3) {
              ListView lv = (ListView) arg0;
              TextView tv = (TextView) lv.getChildAt(arg2);
              String s = tv.getText().toString();
              for(int i=0;i<ss;i++){
                    if(surveyName[i].equals(s)){
                        id=surveyId[i];
                    }
                }
                Intent j=new Intent(SurveyTool.this,Survey.class);
                Bundle d=new Bundle();
                d.putString("surveyId", id);
                d.putString("userId", userId);
                j.putExtras(d);
                startActivity(j);

           }  });
Cool Compiler
  • 857
  • 2
  • 9
  • 20

2 Answers2

1
lv1.setAdapter(new ArrayAdapter<String>(this,R.layout.list_item,surveyName));

replace with this line

mAdapter = new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,surveyName);

hop its working well...

kyogs
  • 6,766
  • 1
  • 34
  • 50
0

may be you try to getting element which is not there please look over this ...

Android: Access child views from a ListView

Community
  • 1
  • 1
Dheeresh Singh
  • 15,643
  • 3
  • 38
  • 36