ButtonID2.setVisibility(View.VISIBLE); seems to the appliaction - android

I have a simple app with two screen fragments.
When the used select a button in want to make one or more other buttons visible on the fragment.
I have set the buttons as invisible in the layut.
When the buttons is clicked the emulalator jumps to the Home screen.
The app is still running and if I click the overview button I can restore the app but the buttons is still not visible.
view.findViewById(R.id.btn1B).setOnClickListener(new view.OnClickListener() {
public void onClick(View view) {
Button ButtonID2 = view.findViewById(R.id.btn1C);
ButtonID2.setVisibility(View.VISIBLE);
Button ButtonID3 = view.findViewById(R.id.btn2C);
ButtonID3.setVisibility(View.VISIBLE);
}
});
FirstFragmant.java
public class FirstFragment extends Fragment {
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
ViewGroup root = (ViewGroup) inflater.inflate(R.layout.fragment_first, null);
return root;
}
public void onViewCreated(#NonNull View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
view.findViewById(R.id.button_first).setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
NavHostFragment.findNavController(FirstFragment.this)
.navigate(R.id.action_FirstFragment_to_SecondFragment);
}
});
view.findViewById(R.id.button_Start).setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
}
});
view.findViewById(R.id.btn1A).setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
Button ButtonID = view.findViewById(R.id.btn1A);
String buttonText = ButtonID.getText().toString();
//get the current timeStamp
Calendar calendar = Calendar.getInstance();
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("dd:MMM:yyyy HH:mm:ss a");
final String strDate = simpleDateFormat.format(calendar.getTime());
MainActivity.gameEvent[0]= strDate;
MainActivity.gameEvent[1] = buttonText;
//CharSequence text = buttonText; //ButtonID.set();
//int duration = Toast.LENGTH_SHORT;
//Toast toast = Toast.makeText( getContext(), strDate + "-" + text, duration);
//toast.show();
}
});
view.findViewById(R.id.btn1B).setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
Button ButtonID2 = view.findViewById(R.id.btn1C);
//ButtonID2.setBackgroundColor(Color.GRAY);
ButtonID2.setVisibility(View.VISIBLE);
Button ButtonID3 = view.findViewById(R.id.btn2C);
ButtonID3.setVisibility(View.VISIBLE);
Button ButtonID1 = view.findViewById(R.id.btn1B);
String buttonText = ButtonID1.getText().toString();
MainActivity.gameEvent[2] = buttonText;
//CharSequence text = buttonText; //ButtonID.set();
//int duration = Toast.LENGTH_SHORT;
//Toast toast = Toast.makeText( getContext(), MainActivity.gameEvent[0] + "," + MainActivity.gameEvent[1] + "," + MainActivity.gameEvent[2], duration);
//toast.show();
}
});
view.findViewById(R.id.btn1C).setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
Button ButtonID = view.findViewById(R.id.btn1C);
String buttonText = ButtonID.getText().toString();
CharSequence text = buttonText; //ButtonID.set();
int duration = Toast.LENGTH_SHORT;
MainActivity.gameEvent[3] = buttonText;
Toast toast = Toast.makeText( getContext(), MainActivity.gameEvent[0] + "," + MainActivity.gameEvent[1] + "," + MainActivity.gameEvent[2] + "," + MainActivity.gameEvent[3], duration);
toast.show();
}
});
}
}

This being your first question, welcome to the site.
Did you set R.id.btn1B to be invisible in the layout as well? What you've done here is you've made btn1C and btn2Cto be visible ONLY AFTER you click onbtn1B, since it's in the click listener; but if btn1B` is also not visible, there's nothing to happen.
As a side note, if you're just learning Android now, you should start with Kotlin instead of Java, it's a much easiest experience. I would set up Kotlin, with DataBinding, and this exact same code will look like this:
viewBinding.btn1B.onClick {
viewBinding.btn1C.visibility = View.VISIBLE
viewBinding.btn2C.visibility = View.VISIBLE
}

Using the debugger I was able to get a better understanding of the object structure.
Button ButtonID2 = view.findViewById(R.id.btn1C); was returning a null. setting a property/attribute caused an error.
Button Btn = view.findViewById(R.id.btn1B) returned the button object within/of the OnClickListener
But Button ButtonID2 = view.findViewById(R.id.btn1C); returns a null.
I instead used getParentFragment().getView() to get the fragments view.
Button ButtonID2 = getParentFragment().getView().findViewById(R.id.btn1C);

Related

Compare data from edit text with data from if statement

I'm making a quiz app. User has to finish the phrase shown on display and write the name of the car in the edittext, after pushing on button, if the answer right, edittext become green, if doesn't, become red. If all answers right (green), intent move on next activity.
I have some difficulties with if statement edit text become red even the answer was right. Also how to make INTENT to move on next activity if all right, if not it doesn't move?
public class MainActivity extends AppCompatActivity {
EditText et_one_one, et_one_two, et_one_three;
Button buttonCheck;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
et_one_one = (EditText) findViewById(R.id.et_one_one);
et_one_two = (EditText) findViewById(R.id.et_one_two);
et_one_three = (EditText) findViewById(R.id.et_one_three);
final String t1 = et_one_one.getText().toString();
final String t2 = et_one_two.getText().toString();
final String t3 = et_one_three.getText().toString();
buttonCheck = (Button) findViewById(R.id.buttonCheck);
buttonCheck.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
if (t1.equals("maserati")){
et_one_one.setBackgroundColor(Color.GREEN);
}
else {
et_one_one.setBackgroundColor(Color.RED);
}
if (t2.equals("mercedes")){
et_one_two.setBackgroundColor(Color.GREEN);
}
else{
et_one_two.setBackgroundColor(Color.RED);
}
if (t3.equals("bmw")){
et_one_three.setBackgroundColor(Color.GREEN);
}
else{
et_one_three.setBackgroundColor(Color.RED);
}
}
});
}
}
You're changing the color of just the et_one_one each time in your if else statements. Shouldn't it be for different edittexts?
buttonCheck.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
boolean allAnswersCorrect = true;
String t1 = et_one_one.getText().toString();
String t2 = et_one_two.getText().toString();
String t3 = et_one_three.getText().toString();
if (t1.equals("maserati")){
et_one_one.setBackgroundColor(Color.GREEN);
}
else {
allAnswersCorrect = false;
et_one_one.setBackgroundColor(Color.RED);
}
if (t2.equals("mercedes")){
et_one_two.setBackgroundColor(Color.GREEN);
}
else{
allAnswersCorrect = false;
et_one_two.setBackgroundColor(Color.RED);
}
if (t3.equals("bmw")){
et_one_three.setBackgroundColor(Color.GREEN);
}
else{
allAnswersCorrect = false;
et_one_three.setBackgroundColor(Color.RED);
}
if(allAnswersCorrect){
Intent intent = new Intent(YourActivity.this, YourSecondActivity.class);
startActivity(intent);
}
}
});
Maintain a allAnswersCorrect boolean to check whether your answers are correct or not. If all are correct the move to your next activity.
You should use t2.equals("maserati"), and it will be ok.

Get value of TextView from Button onClick and pass value to TextView via TextWatcher

What I want my app to do is to calculate an average and display it in a TextView.
I have a layout with two buttons (button0 and button1) and six TextViews. When I press one of the buttons, my app gets the count of the number of clicks it is pressed, and the same thing with the other button. And it also gets the count of the total number of clicks the two buttons are pressed. So if I divide the number of clicks button0 is pressed by the number of total clicks the two buttons are pressed and I multiply it by 100, I get the percentage clicks that button is pressed.
So this is the code:
Button button0, button1;
int click_button0, click_button1;
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_fragment1, container, false);
final TextView times_0_tv = (TextView) view.findViewById(R.id.times_0);
final TextView percentage_0_tv = (TextView) view.findViewById(R.id.percentage_0);
final TextView times_1_tv = (TextView) view.findViewById(R.id.times_1);
final TextView percentage_1_tv = (TextView) view.findViewById(R.id.percentage_1);
final TextView total_clicks_tv = (TextView) view.findViewById(R.id.total_clicks);
button0 = (Button) view.findViewById(R.id.button0);
button1 = (Button) view.findViewById(R.id.button1);
button0.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
click_button0 = click_button0 + 1;
total_clicks = click_button0 + click_button1;
total_clicks_tv.setText(String.valueOf(total_clicks));
if (click_button0 == 1) {
Toast.makeText(getActivity(), "Number 0 has apperared 1 time", Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(getActivity(), "Number 0 has apperared " + click_button0 + " times", Toast.LENGTH_SHORT).show();
}
times_0_tv.setText(String.valueOf(click_button0));
times_1_tv.setText(String.valueOf(click_button1));
}
});
button1.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
click_button1 = click_button1 + 1;
total_clicks = click_button0 + click_button1;
total_clicks_tv.setText(String.valueOf(total_clicks));
if (click_button1 == 1) {
Toast.makeText(getActivity(), "Number 1 has apperared 1 time", Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(getActivity(), "Number 1 has apperared " + click_button1 + " times", Toast.LENGTH_SHORT).show();
}
times_0_tv.setText(String.valueOf(click_button0));
times_1_tv.setText(String.valueOf(click_button1));
}
});
times_0_tv.addTextChangedListener(new TextWatcher() {
#Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
#Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
}
#Override
public void afterTextChanged(Editable s) {
String times0String = times_0_tv.getText().toString();
String times1String = times_1_tv.getText().toString();
String totaltimesString = total_clicks_tv.getText().toString();
// convert the String into a double
if (times0String.length() > 0) {
click_button0 = (int) Double.parseDouble(times0String);
}
if (times1String.length() > 0) {
click_button1 = (int) Double.parseDouble(times1String);
}
if (totaltimesString.length() > 0) {
total_clicks = (int) Double.parseDouble(totaltimesString);
}
// calculate re
double percent0calc = calc_percent0();
// set the label for re1Text
percentage_0_tv.setText(Double.toString(percent0calc));
}
});
times_1_tv.addTextChangedListener(new TextWatcher() {
#Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
#Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
}
#Override
public void afterTextChanged(Editable s) {
String times0String = times_0_tv.getText().toString();
String times1String = times_1_tv.getText().toString();
String totaltimesString = total_clicks_tv.getText().toString();
// convert the String into a double
if (times0String.length() > 0) {
click_button0 = (int) Double.parseDouble(times0String);
}
if (times1String.length() > 0) {
click_button1 = (int) Double.parseDouble(times1String);
}
if (totaltimesString.length() > 0) {
total_clicks = (int) Double.parseDouble(totaltimesString);
}
// calculate re
double percent1calc = calc_percent1();
// set the label for re1Text
percentage_1_tv.setText(Double.toString(percent1calc));
}
});
}
double calc_percent0() {
return click_button0/total_clicks;
}
double calc_percent1() {
return click_button1/total_clicks;
}
Here is a screenshot of the layout:
The problem comes when I press a button, the percentage is 0%, it doesn't change. The idea is, for example, if I press button0 3 times and button1 1 time, percentage for 0 is 75% and percentage for 1 is 25%. Any idea will be welcomed, thanks!
EDIT: I have deleted implemention of TextWatcher and I have added some lines to the code. It is working fine when I click button0 because it shows the percentage of clicks is 100%, but the moment I click button1, both percentages turn 0, and I don't get any percentage. It seems there is a problem when passing the value of the total clicks to the percentage calc.
Here is the code now for the Fragment:
Button button0, button1;
int click_button0, click_button1;
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_fragment1, container, false);
final TextView times_0_tv = (TextView) view.findViewById(R.id.times_0);
final TextView percentage_0_tv = (TextView) view.findViewById(R.id.percentage_0);
final TextView times_1_tv = (TextView) view.findViewById(R.id.times_1);
final TextView percentage_1_tv = (TextView) view.findViewById(R.id.percentage_1);
final TextView total_clicks_tv = (TextView) view.findViewById(R.id.total_clicks);
button0 = (Button) view.findViewById(R.id.button0);
button1 = (Button) view.findViewById(R.id.button1);
button0.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
click_button0 = click_button0 + 1;
total_clicks = click_button0 + click_button1;
total_clicks_tv.setText(String.valueOf(total_clicks));
if (click_button0 == 1) {
Toast.makeText(getActivity(), "Number 0 has apperared 1 time", Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(getActivity(), "Number 0 has apperared " + click_button0 + " times", Toast.LENGTH_SHORT).show();
}
times_0_tv.setText(String.valueOf(click_button0));
times_1_tv.setText(String.valueOf(click_button1));
percent0 = click_button0/total_clicks;
percentage_0_tv.setText(String.valueOf(percent0));
}
});
button1.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
click_button1 = click_button1 + 1;
total_clicks = click_button0 + click_button1;
total_clicks_tv.setText(String.valueOf(total_clicks));
if (click_button1 == 1) {
Toast.makeText(getActivity(), "Number 1 has apperared 1 time", Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(getActivity(), "Number 1 has apperared " + click_button1 + " times", Toast.LENGTH_SHORT).show();
}
times_0_tv.setText(String.valueOf(click_button0));
times_1_tv.setText(String.valueOf(click_button1));
percent1 = click_button1/total_clicks;
percentage_1_tv.setText(String.valueOf(percent1));
}
});
}
Why don't you just calculate and set the percentage in the buttons onClick? You want to update the percentage when the button is clicked, therefore the logic should be within the buttons OnClickListener, not the TextWatcher.
Also, instead of getting the values from your TextViews, use the variables you already have: int click_button0, click_button1;
Do the calculation in the onClick using the variables values and then set the TextViews value and it should work as intended.
Also, if you are going to try and parse a string as a number double, int etc you should surround it in a try catch in case of an exception. And in this case you should just use Integer.parseInt instead of using parseDouble and then casting it to an int.
Edit: Ah yep, that'd be because you are dividing an int by an int, so the result will also be an int. A quick fix is to cast one of the numbers to a float/double, and when you divide you will get a decimal number.
((double) click_button0) / total_clicks;
You should also update both percentages at the same time, seeing as one number changing affects the other.

Get the value bottommost TextView that add programmatically?

I am adding TextView programmatically on LinearLayout :
And then I click on a TextView and I pass IDs and Texts of TextView to another Activity (With SharedPreferences).
But when I get data from SharedPreferences in another activity and see data with Log I just get the ID and Value bottommost TextView.
(For example i just see the data of TextView_3).
But perhaps i had multiple TextView on LinearLayout and i click on 2nd TextView or another TextView but it just get me data of bottommost TextView.
public class ChatPage extends Activity {
TextView[] txt;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.chat_page);
txt = new TextView[totalPersons];
for (int s = 0; s < listOfPersons.getLength(); s++) {
txt[s] = new TextView(ChatPage.this);
if (group.equals("Admin")) {
txt[s].setOnClickListener(new OnClickListener() {
#Override
public void onClick(View arg0) {
startActivity(new Intent(
ChatPage.this,
ConversationPage.class));
editor.putString("Adminid", id);
editor.putString("NameAdmin", name);
editor.commit();
}
});
}
if (group.equals("User")) {
txt[s].setOnClickListener(new OnClickListener() {
#Override
public void onClick(View arg0) {
startActivity(new Intent(
ChatPage.this,
ConversationPage.class));
editor.putString("Userid", id);
editor.putString("NameUser", name);
editor.commit();
}
});
}
}
}
}
Another Activity i get data :
UserID = (shared.getString("Userid", "NULLID"));
UserNAME = (shared.getString("NameUser", "NULLNAME"));
IDAdmin = (shared.getString("Adminid", "NULL_idSharee"));
AdminName = (shared.getString("NameAdmin", "NULL_NameSharee"));
Log.i("test", "UserID " + UserID );
Log.i("test", "UserNAME " + UserNAME );
Log.i("test", "IDAdmin " + IDAdmin );
Log.i("test", "AdminName " + AdminName );
It's a java issue, you need to instantiate new class for each on click listener, you can't do in this way. create a private class in your code
private class MyOnClickListener implements OnClickListener {
private final String mId;
public MyOnClickListener(String id) {
mId= id;
}
public void onClick(View v) {
Intent intent= new Intent(getApplicationContext(), ACtivity.class);
intent.putExtra("current_post_id", mId);
startActivity(intent);
}
}
then
textView.setOnClickListener(new MyOnClickListener(id));
add your views like this:
final View view = getLayoutInflater().inflate(R.layout.yourLayout,
yourLinearLayout, false);
TextView text= (TextView ) view.findViewById(R.id.chapter_page);
view.setTag(unique Id);//your TextView's id that later use in onClick
text.setText(yourText);
goToPage.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View arg0) {
int id = (Integer) view.getTag();//this return clicked textView id
//do some thing...
}
});
yourLinearLayout.addView(view);
you can put this code in loop and add view to linearLayout more than one.
you should provide a unique id to your text view like this
for an example
public void add_Text_view_row(String name,int i){
TextView a = new TextView(getActivity());
a.setText(name);
a.setId(17*i);
linearlayout_your.addView(a);
a.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View arg0) {
// your codes should be here
}
});
}
you can use this method in side a loop.you should pass data to those parameters
Your response is here :
///In your Oncreate
txt[s].setText(usename);
txt[s].setLayoutParams(params);
txt[s].setTextColor(Color.BLACK);
txt[s].setClickable(true);
txt[s].setId(5*s);
txt[s].set
OnClickListener(new listen(s,idTwo,nameTwo));
//----//
////And then create a class
public class listen implements OnClickListener{
int bId;
String Pid;
String Pname;
listenSharee(int _id,String _Pid,String _Pname) {
bId = _id;
Pid = _Pid;
Pname = _Pname;
}
#Override
public void onClick(View v) {
startActivity(new Intent(ChatPage.this,YourClass.class));
editor.putString("Aname", Pid);
editor.putString("Aname", Pname);
editor.commit();
//Toast.makeText(getBaseContext(), txt[bId].getText()+ " * " + Pid + " * " + Pname, Toast.LENGTH_LONG).show();
}
}
Good Luck. ;)

Using a button and then showing dynamic text

I am writing a program that when the user enter a number text appears according to that number. My problem is that the button line has public void ... after this I am trying to use if statements and return methods, but because of the public void, the return method can not return anything. I tried to close the public void, but I am getting errors. Please help.
The code is as follows. I have included the different codes that I have tried like toast, etc..
ente#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button button = (Button)findViewById(R.id.go);
button.setOnClickListener(mAddListener);
// tv = (TextView) findViewById(R.id.textView1);
}
private OnClickListener mAddListener = new OnClickListener()
{
public void onClick(View v) {
}}
;
//Toast.makeText(Num.this, "This Display", Toast.LENGTH_SHORT).show();
//toast.show();
//finish ();
// long id = 0;
// try
{
PleaseEnter=(EditText)findViewById(R.id.PleaseEnter);
{
}
if (PleaseEnter.equals("1"))
// tv.setText("This is the display 1.");
return "This display";
// Context context = getApplicationContext();
// CharSequence text ="this display";
// int duration =Toast.LENGTH_LONG;
// Toast toast =Toast.makeText(context, text, duration);
// toast.show();
else if (PleaseEnter.equals("2"))
return;
//tv.setText("Dispaly 2");
You can define your own method at Activity level, such as:
private void onTextEdited(String content) {
// deal with the String
}
In the onClick method of your OnClickListener, you can call it such as:
public void onClick(View v) {
EditText myEditText = (EditText) findViewById(R.id.PleaseEnter);
onTextEdited(myEditText.getText().toString());
}

How to have data from dialog box to listview in android 2.1?

all
i have created listview dynamically.now i want to change the name of listview/listitems or i want to retrieve content below each row but the content is coming from dialogbox.is it possible to have data from dialogbox in listview?How to achieve this??can any one guide or give some sample code of the same?
Thanks in Advance--
public class Tdate extends Activity
{
private ListView lView;
private String lv_items[] = { "Birth_Date", "Anniversary_Date", "Joining_Date","Meeting_Date","Appraisal_Date","Anniversary_Date", "Joining_Date","Meeting_Date","Appraisal_Date"};
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.tdate);
Button customdate = (Button)findViewById(R.id.customdate);
lView = (ListView) findViewById(R.id.ListView01);
lView.setAdapter(new ArrayAdapter<String>(this,android.R.layout.simple_list_item_multiple_choice, lv_items));
lView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
lView.setOnItemClickListener(new OnItemClickListener()
{
#Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,long arg3)
{
showDateTimeDialog();
}
});
}
private void showDateTimeDialog()
{
// Create the dialog
final Dialog mDateTimeDialog = new Dialog(this);
// Inflate the root layout
final RelativeLayout mDateTimeDialogView = (RelativeLayout) getLayoutInflater().inflate(R.layout.date_time_dialog, null);
// Grab widget instance
final DateTimePicker mDateTimePicker = (DateTimePicker) mDateTimeDialogView.findViewById(R.id.DateTimePicker);
// Check is system is set to use 24h time (this doesn't seem to work as expected though)
final String timeS = android.provider.Settings.System.getString(getContentResolver(), android.provider.Settings.System.TIME_12_24);
final boolean is24h = !(timeS == null || timeS.equals("12"));
// Update demo TextViews when the "OK" button is clicked
((Button) mDateTimeDialogView.findViewById(R.id.SetDateTime)).setOnClickListener(new OnClickListener() {
public void onClick(View v) {
mDateTimePicker.clearFocus();
((TextView) findViewById(R.id.Date)).setText(mDateTimePicker.get(Calendar.YEAR) + "/" + (mDateTimePicker.get(Calendar.MONTH)+1) + "/"
+ mDateTimePicker.get(Calendar.DAY_OF_MONTH));
if (mDateTimePicker.is24HourView()) {
((TextView) findViewById(R.id.Time)).setText(mDateTimePicker.get(Calendar.HOUR_OF_DAY) + ":" + mDateTimePicker.get(Calendar.MINUTE));
} else {
((TextView) findViewById(R.id.Time)).setText(mDateTimePicker.get(Calendar.HOUR) + ":" + mDateTimePicker.get(Calendar.MINUTE) + " "
+ (mDateTimePicker.get(Calendar.AM_PM) == Calendar.AM ? "AM" : "PM"));
}
mDateTimeDialog.dismiss();
}
});
// Cancel the dialog when the "Cancel" button is clicked
((Button) mDateTimeDialogView.findViewById(R.id.CancelDialog)).setOnClickListener(new OnClickListener() {
public void onClick(View v)
{
mDateTimeDialog.cancel();
}
});
// Reset Date and Time pickers when the "Reset" button is clicked
((Button) mDateTimeDialogView.findViewById(R.id.ResetDateTime)).setOnClickListener(new OnClickListener() {
public void onClick(View v)
{
mDateTimePicker.reset();
}
});
// Setup TimePicker
mDateTimePicker.setIs24HourView(is24h);
// No title on the dialog window
mDateTimeDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
// Set the dialog content view
mDateTimeDialog.setContentView(mDateTimeDialogView);
// Display the dialog
mDateTimeDialog.show();
}
}

Categories

Resources