我的代码存在问题。我正在用相机拍照,然后将图像上传到firebase存储。但是,我正在向数据库添加其他数据,它也包含照片网址。上面的脚本开始将图像上传到存储,但代码的其他部分将无法工作,因为this.picurl仅在上载过程完成后才有值。
我怎么能添加一个序列,所以当this.picurl = savepic.downloadURL终于可用时(图片上传成功),其余的代码将会运行。
public class NewActivity extends AppCompatActivity {
protected void onCreate(Bundle savedInstanceState){
ListView listfavorites = findViewById(R.id.favorites);
try{
SQLiteOpenHelper helper = new DataBaseHelper(this);
SQLiteDatabase db = helper.getReadableDatabase();
// Now with this query, my list is filled with all the data, when I tickle
// which object is the favorite.
Cursor favorite = db.rawQuery ("SELECT CARS._id, PLANES._id,
CARS.NAME, PLANES.NAME FROM CARS,
PLANES WHERE
CARS.FAVORITE=1 AND
PLANES.FAVORITE=1, null);
CursorAdapter favoriteAdapter = new
SimpleCursorAdapter(NewActivity.this,
android.R.layout.simple_list_item_1,
favorite,
new String[]{"NAME",
new int[]}{android.R.id.text1},0);
listfavorites.setAdapter(favoriteAdapter);
}catch(SQLite Exception e){
Toast.makeText(this, "Database not available",
Toast.LENGTH_SHORT).show(); }
// By the way, if I already have a list filled up with data and I
// would like to go to the corresponding activity, how to do it if
// the list is filled with eg 2-3 activity?
listfavorites.setOnItemClickListener(new AdapterView.OnItemClickListener(){
public void onItemClick(AdapterView<?> parent, View view, int position, long id){
Intent intent = new Intent(this, Cars.class);
intent.putExtra(Cars.EXTRA_CAR, (int)id);
startActivity(intent);
} });
}
}
答案 0 :(得分:0)
您可以将package loginmenu;
import java.util.Scanner;
public class LoginMenu {
private static String correctPassword;
public static String userPassword;
public static int attemptsCounter;
public static boolean loggedIn;
public static void main(String[] args) {
showMenu();
loginAttempt();
}
public static void showMenu()
// displays a menu and keeps displaying until user chooses the QUIT option
{
int userChoice;
Scanner myScan = new Scanner(System.in);
do {
System.out.println("1. Login");
System.out.println("2. Change Password");
System.out.println("3. Change Attempts");
System.out.println("4. Quit");
userChoice = myScan.nextInt();
switch (userChoice) {
case 1: {
System.out.println("You chose to login.");
loginAttempt();
break;
}
case 2: {
System.out.println("You chose to change password.");
Scanner myNewScan = new Scanner(System.in);
System.out.println("Please enter a password.");
userPassword = myNewScan.nextLine();
break;
}
case 3: {
System.out.println("You chose to change attempts.");
Scanner myNewScan = new Scanner(System.in);
System.out.println("Please enter amount of attempts.");
attemptsCounter = myNewScan.nextInt();
break;
}
case 4: {
System.out.println("You have quit the program.");
break;
}
default: {
System.out.println("Not a valid choice.");
}
}// closes switch
} while (userChoice != 4);
myScan.close();
System.out.println("Goodbye.");
}// closes showMenu1
public static void loginAttempt()
{
Scanner scan = new Scanner(System.in);
while (correctPassword != userPassword) && (attemptsCounter>=5);
{
System.out.println("Please change password and attempts first.");
showMenu();
}
if (userPassword == correctPassword) && (attemptsCounter<=5)
{
System.out.println("You entered the correct password in " + attemptsCounter + " attempts");
}
if (attemptsCounter>=6)
{
System.out.println("You have been locked out.");
}
}
}
块放入当时的回调中,也可以使用async / await来执行此操作:
firebase.list