Как я могу изменить ProgressDialog на ProgressBar?Android

Форум для тех, кто программирует под Android
Ответить
Гость
 Как я могу изменить ProgressDialog на ProgressBar?

Сообщение Гость »


I've returned to old project of mine and slowly fixing things to make it work again. It was android 9-10 when i first started and now i changed it to 13-14. In my java class there is a template like 4 choices but when i click any of them nothing happens and i saw no errors in logcat (also when running) . I was using some clicklisteners and
ProgressDialog for these buttons (it was showing a text like "searching for players..." and then redirecting when it found from the firebase database) but i realised that progressDialog is depreceated. Can it be the reason why it doesnt response to clicks? if so how i can change my code to ProgressBar (i guess it is the alternative) to fix this issue
My code is like below:

Код: Выделить всё

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
final Context context = this;
FirebaseUser firebaseuser = FirebaseAuth.getInstance().getCurrentUser();
uid = firebaseuser.getUid();
user = firebaseuser.getDisplayName();
mDatabase = FirebaseDatabase.getInstance().getReference().child("users").child(uid);
mDatabase_status = FirebaseDatabase.getInstance().getReference().child("users").child(uid).child("status");
kullanici = new database();
kullanici.status(mDatabase,"off");
postListener = new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
if (dataSnapshot != null && dataSnapshot.getValue() != null) {
win =String.valueOf(dataSnapshot.child("win").getValue());
if(win==null){
win="0";
}
lose =String.valueOf(dataSnapshot.child("lose").getValue());
if(lose==null){
lose="0";
}
TextView userinfo = (TextView) findViewById(R.id.kullanicibilgisi);
String newstring = "Hoşgeldin "+user+"<br>Galibiyetler: "+win+"<br>"+"Yenilgiler: "+lose;
userinfo.setText(Html.fromHtml(Html.fromHtml(newstring).toString()));
}
}

@Override
public void onCancelled(DatabaseError databaseError) {
Context context = getApplicationContext();
Toast.makeText(context, "Failed to load post.",
Toast.LENGTH_SHORT).show();
}
};
postListener_status = new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
if (dataSnapshot != null && dataSnapshot.getValue() != null) {
String userstatus =String.valueOf(dataSnapshot.getValue());
if ("on".equals(userstatus)){
dialog.hide();
mDatabase.removeEventListener(postListener);
mDatabase_status.removeEventListener(postListener_status);
Intent intocan = new Intent(MainActivity.this, ikinciekren.class);
startActivity(intocan);
}
}
}

@Override
public void onCancelled(DatabaseError databaseError) {
Context context = getApplicationContext();
Toast.makeText(context, "Failed to load post.",
Toast.LENGTH_SHORT).show();
}
};
mDatabase.addValueEventListener(postListener);
kullanici.status(mDatabase,"info");
setContentView(R.layout.activity_main);
btn = (Button)findViewById(R.id.button4);

btn.setOnClickListener(new View.OnClickListener() {

@Override
public void onClick(View v) {
mDatabase_status.addValueEventListener(postListener_status);
kullanici.status(mDatabase,"waiting");
dialog=new ProgressDialog(context);
dialog.setMessage("Looking for a player, please wait ...");
dialog.setCancelable(false);
dialog.setInverseBackgroundForced(false);
dialog.show();
//Ardından Intent methodunu kullanarak nereden nereye gideceğini söylüyoruz.

}
});

}
thanks in advance.


Источник: https://stackoverflow.com/questions/781 ... rogressbar
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «Android»