hi ,
this is very simple doing the custom alert box just calling the layout
public class TimeActivity extends Activity {
Button startTimeBut,endTimeBut;
final Context context = this;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_time_preparation);
setTitle("Time Preparation");
startTimeBut=(Button)findViewById(R.id.start_time);
endTimeBut=(Button)findViewById(R.id.end_time);
startTimeBut.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
startTime();
Log.d("start buttom:", "Started");
}
});
}
private void startTime() {
// custom dialog
final Dialog dialog = new Dialog(context);
dialog.setContentView(R.layout.start_time);
dialog.setTitle("Title...");
Button ok=(Button)findViewById(R.id.Ok);
Button cancel=(Button)dialog.findViewById(R.id.Dialog_Cancel);
cancel.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
dialog.dismiss();
}
});
dialog.show();
}
}
Note:-------------------------
when we calling the button inside the Dialog weshould add the dilog also
Button cancel=(Button)dialog.findViewById(R.id.Dialog_Cancel);
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<LinearLayout
android:id="@+id/linearLayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<Spinner
android:id="@+id/spinner1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.72" />
<Spinner
android:id="@+id/spinner1"
android:layout_width="158dp"
android:layout_height="wrap_content" />
</LinearLayout>
</LinearLayout>
No comments:
Post a Comment