EditTextとボタンを入れたトーストを作りたいのですが、EditText内に何も入力できず、トーストで見たEditText内の書き方のボタンをクリックすることもできません。
public class MainActivity extends Activity
{
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button New=(Button)findViewById(R.id.button1);
Button save=(Button)findViewById(R.id.button3);
EditText ed1=(EditText)findViewById(R.id.editText1);
final Toast t=new Toast(getApplicationContext());
New.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
ListView l=new ListView(getApplication());
l.setAdapter(new badp(getApplicationContext()));
t.setGravity(Gravity.CENTER_VERTICAL, 0, 0);
t.setView(l);
t.setDuration(Toast.LENGTH_LONG);
t.show();
}
});
}
public class badp extends BaseAdapter
{
Context context;
private badp(Context context) {
// TODO Auto-generated constructor stub
this.context=context;
}
public int getCount() {
// TODO Auto-generated method stub
return 1;
}
public Object getItem(int position) {
// TODO Auto-generated method stub
return null;
}
public long getItemId(int position) {
// TODO Auto-generated method stub
return 0;
}
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
LinearLayout l=new LinearLayout(context);
Button b1=new Button(context);
b1.setText("Save");
EditText ed=new EditText(context);
ed.setGravity(Gravity.CENTER);
// LayoutParams lparams = new LayoutParams();
// ed.setLayoutParams(lparams);
ed.setWidth(5);
ed.setEms(10);
l.addView(ed);
l.addView(b1);
return l;
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
}