I am doing an app that creates an ethereum wallet and send some ether when you touch the button register, it takes about 1 minute to do this, while it happens I want to show a message saying: Creating a wallet, wait please.
When I show the message it won't create the wallet or it will create the wallet but it won't show the message.
PS: If someone knows how to down the time to do this, it will help me a lot.
Thanks
thanks for the help... and the negative.
I have solved it anyway, I leave my solution below:
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.ActivityMain);
errorMsg = new AlertDialog.Builder(this);
button.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
new MyAsyncTasks().execute();
}
});
}
class MyAsyncTasks extends AsyncTask<Void, Void, String> {
// ProgressDialog dialog;
#Override
//It will show a message during your background
protected void onPreExecute() {
dialog = new ProgressDialog(mainActivity.this);
dialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
dialog.setTitle("Add title");
dialog.setMessage("Add message");
dialog.setIndeterminate(true);
dialog.setCanceledOnTouchOutside(false);
dialog.show();
}
#Override
protected void onPostExecute() {
dialog.dismiss(); // Close the Dialog
//Show a window with error or operation succesfully
if(hash.equals("Error")){
displayError("Error", "Error");
dialog.cancel();
}
else{
displayConfirmation("Operation Succesfully");
dialog.cancel();
}
}
#Override
protected String doInBackground(Void... voids) {
dialog.show();
// your code to do you background activity
}
}
Related
I am trying to create a dialog inside a fragment.when I am trying to press on the button and enter the dialog the app collaspe.
I guess the code is not right can you please help me with that?
Here is my code:
private void openDialog(){
Dialog dialog=new Dialog(getContext());
//AlertDialog.Builder builder=new AlertDialog.Builder(getContext());
LayoutInflater layoutInflater=this.getLayoutInflater();
View custom_dialog=getActivity().getLayoutInflater().inflate(R.layout.geo_dialog,null);
dialog.setContentView(custom_dialog);
// add_geofence_radius= custom_dialog.findViewById(R.id.radius_size);
save_btn=custom_dialog.findViewById(R.id.save_btn);
cancel_btn=custom_dialog.findViewById(R.id.cancel_btn);
/* save_btn.setOnClickListener(new View.OnClickListener() {
#Override
}
});
*/
/*cancel_btn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
dialog.cancel();
}
});
*/
// dialog.setTitle("hello");
dialog.show();
}
The best way to show dialog in android is to use "DialogFragments" since they are aware of the lifecycle of the view it is attached on (ie. fragments/activities).
Here is an examples provided in Android docs:
public class PurchaseConfirmationDialogFragment extends DialogFragment {
#NonNull
#Override
public Dialog onCreateDialog(#Nullable Bundle savedInstanceState) {
return new AlertDialog.Builder(requireContext())
.setMessage(getString(R.string.order_confirmation))
.setPositiveButton(getString(R.string.ok), (dialog, which) -> {} )
.create();
}
public static String TAG = "PurchaseConfirmationDialog";
}
To show the dialog use:
new PurchaseConfirmationDialogFragment().show(
getChildFragmentManager(), PurchaseConfirmationDialog.TAG);
For more reference on dialogFragments, checkout : Create a DialogFragment
I don't know if this is common or what. But I only have one Toast when it successfully deleted the data from Realtime Database
here's my code btw.
holder.btndel_stud.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
AlertDialog.Builder alert = new AlertDialog.Builder(context);
alert.setTitle("Delete Student Record");
alert.setMessage("Are you sure you want to delete");
alert.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int which) {
final DatabaseReference databaseReference = FirebaseDatabase.getInstance().getReference("Users");
final String uniqueKey = addingStudentsArrayList.get(position).getUniqueid();
databaseReference.addValueEventListener(new ValueEventListener() {
#Override
public void onDataChange(#NonNull DataSnapshot snapshot) {
databaseReference.child(uniqueKey).removeValue().addOnCompleteListener(new OnCompleteListener<Void>() {
#Override
public void onComplete(#NonNull Task<Void> task) {
if(task.isSuccessful()){
Toast.makeText(context, "Student Account/Record has been deleted..", Toast.LENGTH_SHORT).show();
}
else {
Toast.makeText(context, "Something went wrong...", Toast.LENGTH_SHORT).show();
}
}
});
}
#Override
public void onCancelled(#NonNull DatabaseError error) {
Toast.makeText(context, error.getMessage(), Toast.LENGTH_SHORT).show();
}
});
}
});
alert.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int which) {
Toast.makeText(context, "Cancelled", Toast.LENGTH_SHORT).show();
dialog.dismiss();
}
});
alert.show();
}
});
}
basically it toast twice on my mobile phone, even tho I called it only once. But yeah it toast once in my emulator. I genuinely don't know what's happening since there's no message indicating why it's toasting twice.
Toast.makeText(context, "Student Account/Record has been deleted..", Toast.LENGTH_SHORT).show();
The solutions I've tried:
Reinstall the app on my phone, clear cache and clear storage but no luck. Thank you!
I was using gmail, I found that gmail app can access google calendar and contacts under google apps tag in navigation drawer. My point is, how we can access another app. I have made two separate apps and I want to give such link in my third app.
Friends,
Recently, on some google search I found that
private String packge_name = "com.android.calculator2";
private String class_name = "com.android.calculator2.Calculator";
private Button bt;
Then put the code
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
bt = (Button) findViewById(R.id.button1);
bt.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
launchCall();
}
});
}
protected void launchCall() {
// TODO Auto-generated method stub
Intent intent = new Intent();
intent.setAction(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_LAUNCHER);
intent.setComponent(new ComponentName(packge_name, class_name));
try {
startActivity(intent);
} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}
}
I am getting the following error after creating new project
Error:Failed to resolve: com.android.support:design:23.+
Install Repository and sync project
Show in Project Structure dialog
Error:Failed to resolve: com.android.support:appcompat-v7:23.4.0
Install Repository and sync project
Show in Project Structure dialog
Here is the screenshot
I found some information about this problem. After that I searched for updates of the Android support repository and Google repository. I found an update for the Google repository and updated it. Now my all SDK and studio is updated.
How do I deal with this error now?
public class test1 extends AppCompatActivity {
private int conte = 100;
private String b;
String i="CONFIRM";
EditText vared;
int level=1;
private TextView end,leevel;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_test1);
getSupportActionBar().hide();
new Handler().postDelayed(new Runnable() {
#Override
public void run() {
Toast.makeText(test1.this,"زما شما به اتمام رسید !!!", Toast.LENGTH_LONG).show();
Intent i = new Intent(test1.this, test2.class);
startActivity(i);
finish();
}
},100000);
end=(TextView)findViewById(R.id.textView4);
new Thread(){
#Override
public void run() {
while (conte>=0){
runOnUiThread(new Runnable() {
#Override
public void run() {
end.setText(conte+"");
conte--;
}
});
try {
sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}.start();
leevel=(TextView)findViewById(R.id.textView8);
vared=(EditText)findViewById(R.id.vared) ;
Button b2 = (Button) findViewById(R.id.button2);
b2.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
String b = vared.getText().toString();
Toast.makeText(test1.this,"ذخیره شد حالا میتونی امتحان کنی !", Toast.LENGTH_LONG).show();
}
});
if( i==b) {
Button b1 = (Button) findViewById(R.id.button);
b1.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
level++;
leevel.setText(level + "");
}
});
}else {
Toast.makeText(test1.this,"اسم وارد شده صخیخ نمیباشد !", Toast.LENGTH_LONG).show();
}
}
}
My question is how do i send data written in EditText of dialogue box by clicking button and display it on LIstView of Main Activity. ?
public class TaskDetailsActivity extends Activity implements OnClickListener{
String[] timepass= new String[100];
#Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.taskdetails);
//timepass[0] = "sidd";
/*ListView tasklist= (ListView)findViewById(R.id.listview);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(getApplicationContext(), R.layout.insideaddtask, R.id.tp, timepass);
tasklist.setAdapter(adapter);*/
}
public void addnewtask(View view)
{
showDialog(1);
}
#Override
protected Dialog onCreateDialog(int id)
{
Dialog dialog=null;
switch (id)
{
case 1: dialog = new Dialog(TaskDetailsActivity.this);
dialog.setContentView(R.layout.addtask);
Button task_add_ok = (Button)findViewById(R.id.btn_ok);
task_add_ok.setOnClickListener(new OnClickListener()
{
#Override
public void onClick(View arg0)
{
EditText writetask = (EditText)findViewById(R.id.txt_writetask);
String data = writetask.getText().toString();
timepass[0] = data;
}
});
break;
default:
break;
}
return dialog;
}
#Override
public void onClick(View v)
{
// TODO Auto-generated method stub
}
}
you can use any adapter for this arrayadapter of type string...
and use the button's onclick method to populate the listview...
below link provides a good example...
http://android.amberfog.com/?p=296
www.androidhive.info/2011/10/android-listview-tutorial/