0

Hi I have 49 edittexts in my app for which I used gridview. So, I created an activity whose onCreate() method contains the adapter object. In the custom adapter class I gave count=49. So, 49 edittexts are arranged in the gridview.

But my problem is I want to set some values in the edittexts by default as soon as my activity is visible.(hint attribute doesn't not work in my app, as my default values in the edittexts are generated randomly ). So, after a lot of thinking I retrieved the edittexts' objects by using the following code snippet in my activity class and kept this code in one method.

 int k=0;
    for(int i=0;i<editText.length;i++)
      {
        for(int j=0;j<editText.length;j++)
           {
               editText[i][j]=(EditText)gridView.getChildAt(k);
               k++;

            }
      }

But this method should be called before the activity is visible. At the very first time I kept this snippet in the onCreate() method after the statement gridView.setAdapter(new TextAdapter(this)); . But no use, the application is showing force close. Later I kept this in onStart(), but no use again, the edittext objects are still unavailable and showing force close. So, to test this, I kept in one method which gets executed when the button is clicked in the activity, then the edittexts objects are available. So, I don't want to set the values after the manual operation(here button click). I want the values to be set automatically before the activity becomes visible. Still any call back methods which solve my problem? I have been searching many sources for this problem and kinda exhausted. Please suggest. Code snippet would be appreciated.

4

1 回答 1

0

但我的问题是我想在我的活动可见时默认在编辑文本中设置一些值。

不,你没有。您希望在小部件可见EditText之前默认在小部件中设置一些值。EditText

但是应该在活动可见之前调用此方法。

它不应该被写出来,更不用说被调用了。

但没有用,应用程序显示强制关闭。

当然。此时,您的EditText小部件正好为零。

还有什么回调方法可以解决我的问题吗?

当您的, in (或者,如果这是 a )EditText创建小部件时,填充您的小部件。根据定义,您不能在此之前执行此操作,因为小部件不存在。TextAdaptergetView()newView()CursorAdapterEditText

于 2012-09-12T13:07:24.127 回答