Val
Val

Reputation: 4366

Adapter & ListView

I want to get list. Each line - mas[i]. Numb - it's int. I got an eclipse error:

The constructor ArrayAdapter(new View.OnClickListener(){}, int, String[]) is undefined

 public class FirstActivity extends ListActivity {
   public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    findViewById(R.id.button1).setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            TextView NumbZK = (TextView)findViewById(R.id.editText2);   
            final int Numb = Integer.parseInt(NumbZK.getText().toString()); 

            TextView modN = (TextView)findViewById(R.id.editText1); 
            final int N = Integer.parseInt(modN.getText().toString());  

            String[] mas = new String[N];
            for (int i=0; i<N;i++){
                mas[i]=Integer.toString(Numb%(i+1));
            }
            ListView lView = (ListView)findViewById(R.id.list);
            lView.setAdapter(new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1, mas));


        }
    });
 }
}

XML:

<ListView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/list"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:drawSelectorOnTop="false"
    />

help

Upvotes: 0

Views: 292

Answers (4)

Yashwanth Kumar
Yashwanth Kumar

Reputation: 29121

mas[i]=""+(Numb%(i+1));

consider replacing the above line with

mas[i] = "" + Integer.toString(Numb%(i+1));

after looking at your xml,

ListView lView = (ListView)findViewById(R.id.lView);

replace this with

ListView lView = (ListView)findViewById(R.id.list);

and also

lView.setAdapter(new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1, mas));

with

lView.setAdapter(new ArrayAdapter<String>(youractivity.this,android.R.layout.simple_list_item_1, mas));

this should be replaced by context , this method will not work for onclicklistener.

HTH.

Upvotes: 0

aromero
aromero

Reputation: 25761

If your Activity is extending from ListActivity you need to declare a ListView with android:id="@android:id/list" in your layout. Then you can get the ListView by calling getListView() in your Activity

Reference: http://developer.android.com/reference/android/app/ListActivity.html

Upvotes: 2

Carnal
Carnal

Reputation: 22064

android:id="@+id/lView"

Since that's what your looking for in your activity.

Upvotes: 0

user840754
user840754

Reputation: 456

Try adding:

<ListView android:id="@android:id/lView/>

In the layout file

Upvotes: -1

Related Questions