我想做一個烤麪包,我已經把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;
}
}
感謝對話框我做到了:d – maddygoround 2012-08-10 02:01:06