1 つのダイアログをトリガーするゲーム ビューがあり、ここから 2 番目のダイアログがトリガーされます。
この 2 番目のダイアログには、2 つのボタンと 1 つのスピナーがあります。私が抱えている問題は、動的データを使用して、ビュー内にスピナーを表示することです。
基本的に、ボタンがクリックされたときにスピナーをポップアップして、関連するすべてのデータを一覧表示する必要があります。3 つの異なる ArrayLists (1 つの文字列と 2 つの整数) があり、それぞれのスピナーの選択に動的に追加する必要がある個別の情報を保持します。
pt1 - ArrayLists1
ArrayLists2
ArrayLists3
pt2 - ArrayLists1
ArrayLists2
ArrayLists3
Spinner XML レイアウト コード:
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal">
<Button android:text="@string/attack"
android:id="@+id/Attack"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<Button android:text="@string/useitem"
android:id="@+id/UseItemBtn"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<Spinner android:text="@string/useitem"
android:id="@+id/UseItemSpin"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:visibility="gone" />
<Button android:text="@string/equipweapon"
android:id="@+id/EquipWeapon"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
スピナーのクリックをトリガーするために現在使用しているコードは次のとおりです(ここのログがトリガーされます):
import android.widget.AdapterView.OnItemSelectedListener;
@Override
public void onClick(View clicked)
{
if(clicked.getId() == R.id.UseItemBtn)
{
Spinner spinner = (Spinner) findViewById(R.id.UseItemSpin);
ArrayList<String> arrayList1 = new ArrayList<String>();
arrayList1.add("test item the first one");
arrayList1.add("really long list item - section 2 goes here - finally section 3");
ArrayAdapter<String> adp = new ArrayAdapter<String> (context,android.R.layout.simple_spinner_dropdown_item,arrayList1);
// APP CURRENTLY CRASHING HERE
spinner.setAdapter(adp);
//Set listener Called when the item is selected in spinner
spinner.setOnItemSelectedListener(new OnItemSelectedListener()
{
public void onItemSelected(AdapterView<?> parent, View view, int position, long arg3)
{
String city = "The city is " + parent.getItemAtPosition(position).toString();
Toast.makeText(parent.getContext(), city, Toast.LENGTH_LONG).show();
}
public void onNothingSelected(AdapterView<?> arg0)
{
// TODO Auto-generated method stub
}
});
}
BattleRun.show();
}
このクリックで動的スピナーを追加するにはどうすればよいですか。これに加えて、スピナーがクリックされたときに、理想的には、実際のスピナー内に送信ボタンを配置して、選択する前に選択肢をフリックできるようにしたいと考えています (常に表示されている必要があります)。
最後に、項目がスピナーで選択されて送信されると、前のダイアログが新しいデータで自動的に更新されます (これは簡単に行うことができます)。
さらにコード スニペットが必要な場合はお知らせください。ヘルプやガイダンスをいただければ幸いです。
ありがとう、L & L パートナー