次のコードを使用して、子 LinearLayout の下のレイアウトでビューを膨張させています。
LayoutInflater vi = (LayoutInflater)getApplicationContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View v = vi.inflate(R.layout.your_layout, null);
// fill in any details dynamically here
TextView textView = (TextView) v.findViewById(R.id.a_text_view);
textView.setText("your text");
// insert into main view
View insertPoint = findViewById(R.id.insert_point);
((ViewGroup) insertPoint).addView(v, 0, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT));
しかし、私はそこに私の見解を見ることができません。画面を横向きに回転すると表示されます。これを修正する方法は?
編集:
これが基本的に私がやっていることです。2 つのタブを持つ TabActivity があります。TabActivity のフラグと TabHost を格納するアプリケーション グローバルを使用します。また、フラグを監視するためにアプリケーション グローバルを継続的に監視している 2 番目のタブ アクティビティでスレッドを使用しています。最初のタブでボタンをクリックすると、グローバルを true に設定します。2 番目のタブのスレッドは、その値をチェックします。true になったら、非同期タスクを実行し、ApplicationGlobal で攪拌した TabHost を使用して、現在表示されているウィンドウを 2 番目のタブに移動します。
2 番目のタブのコード:
public class ShowDownloadsActivity extends Activity {
private List<String> list;
ApplicationGlobal ap;
String tempUrl = "";
LinearLayout lly;
LayoutInflater inflater;
Context con;
static int k = 0;
static int tmp = 0;
static int size = 0;
View insertPoint;
View v;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.shwds);
con = this;
v = LayoutInflater.from(this).inflate(R.layout.downloadlistrow, null);
insertPoint = (View) findViewById(R.id.layout_vids);
inflater = (LayoutInflater) con.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
ap = (ApplicationGlobal) getApplication();
lly = (LinearLayout) findViewById(R.id.layout_vids);
Thread thread1 = new Thread() {
public void run() {
try {
boolean flg = ap.getFlag();
if (flg) {
tempUrl = ap.getUrl();
ap.setUrl("");
flg = false;
new downloadVideo().execute();
}
} catch (Exception e) {
e.printStackTrace();
}
}
};
thread1.run();
}
class downloadVideo extends AsyncTask<Hashtable<String, String>, String, String> {
String resp = "";
protected void onProgressUpdate(String... values) {
}
@Override
protected void onPreExecute() {
// fill in any details dynamically here
TextView textView = (TextView) v.findViewById(R.id.siz);
textView.setText("your text");
// insert into main view
addContentView(v, new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT));
super.onPreExecute();
}
@Override
protected String doInBackground(Hashtable<String, String>... prmss) {
try {
final int return resp;
}
@Override
protected void onPostExecute (String result){
super.onPostExecute(result);
}
}
}
}