だから私はAndroidのダイアログについて読んでいて、これを現在のコードに実装する方法に興味があります.
Androidのドキュメントに従って、カスタムレイアウトを作成しました。新しいクラスとして作成しました。
public class AddSiteDialog extends DialogFragment {
public Dialog onCreateDialog(Bundle savedInstanceState) {
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
LayoutInflater inflater = getActivity().getLayoutInflater();
builder.setView(inflater.inflate(R.layout.main, null))
.setPositiveButton(R.string.signin, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int id) {
//To change body of implemented methods use File | Settings | File Templates.
}
})
.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
AddSiteDialog.this.getDialog().cancel();
}
});
return builder.create();
}
}
ViewPager レイアウト内のボタンをクリックすると、そのダイアログが表示されるようになりました。別のクラスで。public class FieldsActivity extends Activity {
私はViewPagerを持っています。
private class MyPagerAdapter extends PagerAdapter {
final ViewPager mPager = (ViewPager) findViewById(R.id.fieldspager);
public int getCount() {
return 3;
}
public Object instantiateItem(View collection, int position) {
LayoutInflater inflater = (LayoutInflater) collection.getContext()
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
ListView lv = (ListView)findViewById(android.R.id.list);
final ArrayList<String> siteList = new ArrayList<String>();
final ArrayAdapter<String> aa;
aa = new ArrayAdapter<String>(getBaseContext(), R.layout.list_row, siteList);
if(lv == null) Log.v("lv", "null");
else Log.v("aa", "null");
if (lv != null) {
lv.setAdapter(aa);
}
int resId = 0;
View view = null;
switch (position) {
case 0:
resId = R.layout.field01;
view = inflater.inflate(resId, null);
((ViewPager) collection).addView(view, 0);
return view;
case 1:
resId = R.layout.add_site;
view = inflater.inflate(resId, null);
Button addSiteButton = (Button)view.findViewById(R.id.addSiteButton);
((ViewPager) collection).addView(view, 0);
addSiteButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//I want to click this button and the dialog show up
}
});
return view;
そこでこれをどのように実装しますか。
私はこれにかなり慣れていないので、物事がどのように互いに通信するかを理解しようとしています.
ありがとう!