ログイン時にユーザーキューの各メッセージのテキストビューを含むダッシュボードを作成しようとしています。このためのビューは動的に構築する必要があるため、キュー内のメッセージ数ごとにレイアウトを拡張しています。レイアウトには、各メッセージの内容(送信者、メッセージ、時間など)に応じて変化する3つのテキストビュー要素を持つ直線レイアウトのみがあります。レイアウトを拡張した後、空白のコンテナのみが膨張したビュー内にテキストは表示されません。私は2番目のパラメータとしてnullを呼び出すようにinflateメソッドを変更しようとしました。また、3番目のパラメータを省略するとデフォルト(true)が無用になりました。あなたの助けを前にありがとう。inflate()の後にTextViewボックスにテキストが表示されない
activity_dash_board.xmlからactivity_dash_board_paging_queue.xml<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="80dp"
android:layout_gravity="top"
android:weightSum="1"
android:id="@+id/LL_pagingQueue"
android:background="#ffffff"
android:paddingTop="2dp"
android:paddingBottom="2dp"
android:gravity="top"
android:showDividers="end"
android:divider="#a41515">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="@string/TV_pagingRequester"
android:id="@+id/TV_pagingRequester" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="@string/TV_pagingMessage"
android:id="@+id/TV_pagingMessage" />
<TextView
android:layout_width="46dp"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="@string/TV_pagingTime"
android:id="@+id/TV_pagingTime"
android:layout_gravity="right" />
</LinearLayout>
からDashBoardAsync.java
public class DashBoardAsync extends AsyncTask<Void, Integer, Boolean> {
public static String[][] m_organizationPagingQueue = new String[3][3];
private LinearLayout m_LL_container;
private LinearLayout m_LL_queue;
private Context m_C_context;
public DashBoardAsync(Context context, LinearLayout container, LinearLayout queue){
m_C_context = context;
m_LL_container = container;
m_LL_queue = queue;
}
//doInBackground omitted
@Override
protected void onPostExecute(Boolean result){
LayoutInflater inflater = (LayoutInflater)m_C_context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
for(int a = 0; a < 2; ++a) {
View inflatedView = inflater.inflate(R.layout.activity_dash_board_paging_queue, m_LL_container, false);
TextView requester = (TextView)inflatedView.findViewById(R.id.TV_pagingRequester);
requester.setText("This is some text");
TextView message = (TextView)inflatedView.findViewById(R.id.TV_pagingMessage);
message.setText("This is some text");
m_LL_container.addView(inflatedView);
}
super.onPostExecute(result);
}
からactivity_dash_board.java
public class DashBoardActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_dash_board);
// Create Async object for network processing
DashBoardAsync m_processDashboard = new DashBoardAsync(getApplicationContext(), (LinearLayout)findViewById(R.id.LL_dashboardContainer), (LinearLayout)findViewById(R.id.LL_pagingQueue));
// Get the info passed from the LoginActivity
Bundle extras = getIntent().getExtras();
}
から
postExecute
実行おそらく、あなたのビューが完全に作成されていない
Layout with inflated View containing blank textviews
Preview of activity_dash_board_paging_queue.xml
ご回答いただきありがとうございます。残念ながら問題は解決しませんでした。私は自分のアクティビティの中でonResumeメソッドを追加し、DashBoardAsyncオブジェクトの初期化とその内部のexecuteメソッドの呼び出しを移動しましたが、まだ空白を表示します – xec86
@ xec86 'getApplicationContext() ' –
コンテキストは重要ではありません。 LayoutInflaterを取得するだけです。 –