내 activity_main.xml ScrollView에 양식을 생성하고 싶습니다. XML을로드하고 올바르게 구문 분석하지만 addView (LinearLayout)를 시도하면 예외 e가 발생합니다. 내 응용 프로그램은 푸시 알림을 통해 XML 파일의 URL을 가져 와서 파싱합니다. XML에 따르면 양식을 생성하여 사용자에게 표시해야합니다. https://www.ibm.com/developerworks/xml/tutorials/x-andddyntut/#l1 다음XML의 동적 안드로이드 폼
내 주요 활동 :
public class MainActivity extends Activity {
// label to display gcm messages
TextView lblMessage;
Controller aController;
public ScrollView sv;
Button execute;
// Asyntask
AsyncTask<Void, Void, Void> mRegisterTask;
public static String name;
public static String email;
final Context context = this;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ScrollView sv = (ScrollView) findViewById(R.id.sv);
...
}
// Create a broadcast receiver to get message and show on screen
private final BroadcastReceiver mHandleMessageReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
String newMessage = intent.getExtras().getString(Config.EXTRA_MESSAGE);
// Waking up mobile if it is sleeping
aController.acquireWakeLock(getApplicationContext());
ScrollView sv = (ScrollView) findViewById(R.id.sv);
new DoInBackground(getApplicationContext(), sv).execute(newMessage);
// Releasing wake lock
aController.releaseWakeLock();
}
};
여기 내 비동기 클래스입니다 : 나는 주요 활동의 맥락과도 생각
public class DoInBackground extends AsyncTask<String, Void, Void> {
Context mContext;
ScrollView mSv;
String tag = "DynamicFormXML";
XmlGuiForm theForm;
ProgressDialog progressDialog;
Handler progressHandler;
public DoInBackground(Context context, ScrollView sv) {
this.mContext = context;
this.mSv = sv;
}
@Override
protected void onPreExecute() {
super.onPreExecute();
}
@Override
protected Void doInBackground(String... params) {
if (GetFormData(params[0])) {
DisplayForm();
}
else
{
Log.e(tag,"Couldn't parse the Form.");
AlertDialog.Builder bd = new AlertDialog.Builder(mContext);
AlertDialog ad = bd.create();
ad.setTitle("Error");
ad.setMessage("Could not parse the Form data");
ad.show();
}
return null;
}
protected void onPostExecute() {
}
private boolean DisplayForm()
{
try
{
final LinearLayout ll = new LinearLayout(mContext);
mSv.addView(ll); //Here it fails
ll.setOrientation(android.widget.LinearLayout.VERTICAL);
...
} catch (Exception e) { // Goes to here
Log.e(tag,"Error Displaying Form");
return false;
}
}
나는 예제로 이것을 사용 주 활동의 빈 Scrollview가 올바르게 전달됩니다 (null이 아님).하지만 100 % 확실하지는 않습니다. 어떤 도움/힌트를 부탁드립니다! :)