package org.abcd.test;import android.app.Activity; import android.os.Bundle; import android.widget.LinearLayout; import android.widget.LinearLayout.LayoutParams; import android.widget.TextView;public class MainActivity extends Activity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main);
String htmlStr="{\"username\":\"Kelly\",\"email\":\"[email protected]\",\"telephone\":\"88888888\"}"; TextView tv1 = new TextView(this); LinearLayout layout = new LinearLayout(this); layout.setOrientation(LinearLayout.HORIZONTAL); layout.addView(tv1); addContentView(layout, new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
04-18 15:21:08.986: I/System.out(477): [{"username":"Kelly","email":"[email protected]","telephone":"88888888"}]我就是想问一下xml中应该如何写,把这些数据显示在xml界面中?
package org.abcd.test;import android.app.Activity;
import android.os.Bundle;
import android.widget.LinearLayout;
import android.widget.LinearLayout.LayoutParams;
import android.widget.TextView;public class MainActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
String htmlStr="{\"username\":\"Kelly\",\"email\":\"[email protected]\",\"telephone\":\"88888888\"}";
TextView tv1 = new TextView(this);
LinearLayout layout = new LinearLayout(this);
layout.setOrientation(LinearLayout.HORIZONTAL);
layout.addView(tv1);
addContentView(layout, new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
htmlStr = htmlStr.replace("{", "").replace("}", "").replace("\"", "").replace(",", "\n");
tv1.setText(htmlStr); }
}