0
私のアプリケーションでは、PopupDialog
の中にListView
を使用しようとしています。これはAsyncTask
の内部で行われます。問題はonPreExecute
とonPostExecute
の間にあると思います.....すべてが正しく返されますが、findViewById()
を使用した後はlist = null
となります。私は理由を理解できません...... AsyncTaskとAdapterはどちらも内部クラスです。PopupDialog内のListViewがnullです
protected void onPreExecute() {
AlertDialog.Builder alert = new AlertDialog.Builder(CreateNewReport.this);
LayoutInflater inflater = LayoutInflater.from(CreateNewReport.this);
popupView = inflater.inflate(R.layout.add_expenses, null);
alert.setTitle("Add Expenses").setView(popupView);
alert.setNeutralButton("Save", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
}
});
alert.show();
}
protected void onPostExecute(List<Expense> expenses){
availableExpenses = expenses;
// create list adapter for available expenses
ArrayAdapter<Expense> adapter = new ArrayAdapter<Expense>(CreateNewReport.this,
android.R.layout.simple_list_item_1, expenses);
// get a reference to the list
final ListView list = (ListView) findViewById(R.id.listViewAvailableExpenses);
// set the list adapter
list.setAdapter(adapter);
// find widgets
final ProgressBar progress = (ProgressBar) findViewById(R.id.loading_expenses);
final LinearLayout listLayout = (LinearLayout) findViewById(R.id.available_expenses);
final LinearLayout progressContainer = (LinearLayout) findViewById(R.id.available_expenses_loading);
// change visibility as needed
progressContainer.setVisibility(View.INVISIBLE);
progress.setVisibility(View.INVISIBLE);
listLayout.setVisibility(View.VISIBLE);
}
ポップアップボックスのXML
findViewById()
呼び出しは(それがアクティビティインスタンスのメソッドです)活動中にあなたのリストを探していますが、あなたのリストが内部にありますので、
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<ProgressBar
android:id="@+id/loading_expenses"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="@android:style/Widget.ProgressBar.Large"
android:layout_centerInParent="true"
/>
<ListView
android:id="@+id/listViewAvailableExpenses"
style="@style/Container"
android:cacheColorHint="#00000000"
/>
</RelativeLayout>
スポットをオンにする必要があります。それはまさに正しいものでした。 – Cody