對於相應的模式,佈局和佈局平面中有兩個不同的xml文件。由於我想在edittext中將值重新設置,即使方向更改,我在清單文件中使用android:configChanges="orientation|keyboardHidden"
。這會再次禁用onCreate()方法的執行,並且當前活動不會被銷燬。爲什麼無法在onConfigurationChanged()中的edittext上設置值?
我在我的應用程序中有兩個框架。第一幀包含25個edittext,第二幀包含10個按鈕。因此,在縱向模式下,這些幀依次排列在一個接一個的橫向模式中。爲了根據模式得到這個視圖,我在方法中寫了setContentView(R.layout.main);
。但是我的問題在於,我能夠將已輸入的值存儲在的editText中。但設置爲相應的佈局後,我無法將這些值設置回edittext。因爲我正在獲取相應的佈局,但使用空的edittext。以下代碼片段給出了我的問題的概述。
public void onCreate()
{
setContentView(R.layout.main);
gridView = (GridView) findViewById(R.id.gridView1);
gridView.setAdapter(new EditTextAdapter(this)); //This creates 25 edittexts in the gridview which is in first frame.
}
public void getEditTexts()//getting the edittext objects here in the activity class
{
editText1=gridView.getChildAt(k);
...........
...........
}
public void onConfigurationChanged()
{
String s1=editText1.getText().toString();//Here I am using technique to store the values.
setContentView(R.layout.main);
gridView.setAdapter(new EditTextAdapter(this));
getEditTexts();
editText1.setText(s1); //here is my problem. I am unable to set values back in the editText.
}
我在哪裏出錯了?如果在先前的模式下設置值,在當前模式下如何在25個edittext中設置這些值。請建議。在這裏,我猜這些值是在舊的edittext對象本身中設置的,即使模式被改變了。如何設置新的edittext對象中的值?如果舊編輯文本對象中的值沒有出現在當前佈局中,它們是如何設置的?或者還有這個問題的另一個原因?
您正在使用網格視圖和編輯文本作爲它的項目。你如何處理GridView的回收?導致每次滾動網格時視圖都會被回收。 – karn
我將verticalScrollbarEnabled設置爲false。所以,滾動條被禁用。 – Spike
看着這個帖子..它會解決你的回收問題.. http://stackoverflow.com/questions/4523609/grid-of-images-inside-scrollview/4536955#4536955。 – karn