我无法连接布局。它们不会在Android Studio中显示

时间:2018-02-28 06:16:17

标签: java android android-layout layout

我是Android Studio的新手。我想连接layouts.But当我执行项目并选择它不会在Android Studio中显示的配置文件页面。我执行时没有收到任何错误或警告项目

这是我要连接的布局

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/linearlayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/graylight"
    android:orientation="vertical"
    tools:context=".Profile">

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@drawable/gradientbackground"
        android:orientation="vertical">

        <ImageView
            android:id="@+id/profilePhoto"
            android:layout_width="200dp"
            android:layout_height="100dp"
            android:layout_gravity="center_horizontal"
            android:layout_margin="25dp"
            android:contentDescription="@string/todo"
            android:onClick="chooseImage"
            android:src="@drawable/ic_account_circle_black_24dp"
            tools:ignore="OnClick" />

        <EditText
            android:id="@+id/nameText"
            android:layout_width="160dp"
            android:layout_height="wrap_content"
            android:layout_gravity="center_horizontal"
            android:hint="@string/enter_your_name"
            android:textColor="#fff"
            android:textSize="18sp"
            android:textStyle="bold" />

    </LinearLayout>
</RelativeLayout>

<LinearLayout
    android:layout_width="300dp"
    android:layout_height="wrap_content"
    android:layout_gravity="center"
    android:layout_marginTop="45dp">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:paddingStart="20dp">

        <ImageView
            android:layout_width="40dp"
            android:layout_height="40dp"
            android:contentDescription="@string/todo"
            android:src="@drawable/email" />

        <EditText
            android:id="@+id/emailText"
            android:layout_width="240dp"
            android:layout_height="wrap_content"
            android:hint="@string/enter_your_email"
            android:inputType="textEmailAddress"
            android:paddingStart="20dp" />
    </LinearLayout>
</LinearLayout>

<LinearLayout
    android:layout_width="300dp"
    android:layout_height="wrap_content"
    android:layout_gravity="center"
    android:layout_marginTop="45dp">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:paddingStart="20dp">

        <ImageView
            android:layout_width="40dp"
            android:layout_height="40dp"
            android:contentDescription="@string/todo"
            android:src="@drawable/phone" />

        <EditText
            android:id="@+id/phoneText"
            android:layout_width="240dp"
            android:layout_height="wrap_content"
            android:hint="@string/enter_your_phone"
            android:inputType="phone"
            android:paddingStart="20dp" />
    </LinearLayout>
</LinearLayout>

<Button

    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center_horizontal"
    android:layout_marginTop="20dp"
    android:background="@drawable/buttonstyle"
    android:onClick="save"
    android:text="@string/save"
    tools:ignore="OnClick" />

public class profile_info extends ArrayAdapter<String> {

private final ArrayList<String> userName;
private final ArrayList<String> userEmail;
private final ArrayList<String> UserPhone;
private final ArrayList<String> userProfileImage;
private final Activity context;

public profile_info(ArrayList<String> userName, ArrayList<String> userEmail, 
ArrayList<String> userPhone, ArrayList<String> userProfileImage, Activity 
context) {
    super(context,R.layout.custom_profileinfo,userEmail);
    this.userName = userName;
    this.userEmail = userEmail;
    UserPhone = userPhone;
    this.userProfileImage = userProfileImage;
    this.context = context;
}

@NonNull
@Override
public View getView(int position, @Nullable View convertView, @NonNull 
ViewGroup parent) {

    LayoutInflater layoutInflater =context.getLayoutInflater();
    View profileinfo 
    =layoutInflater.inflate(R.layout.custom_profileinfo,null,true);
    EditText userNametext =profileinfo.findViewById(R.id.nameText);
    EditText userEmailtext =profileinfo.findViewById(R.id.emailText);
    EditText userPhonetext =profileinfo.findViewById(R.id.phoneText);
    ImageView  userImage = profileinfo.findViewById(R.id.profilePhoto);

    userNametext.setText(userName.get(position));
    userEmailtext.setText(userEmail.get(position));
    userPhonetext.setText(UserPhone.get(position));
    Picasso.with(context).load(userProfileImage.get(position)).into(userImage);

    return profileinfo;
}
}

我想将custom_profileinfo连接到activity_profile

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.cat.haberuygulamasi.Profile">
<ListView
    android:id="@+id/listView"
    android:layout_width="match_parent"
    android:layout_height="match_parent"/>

public class Profile extends AppCompatActivity {

ArrayList<String> userEmailFromFB;
ArrayList<String> userImageFromFB;
ArrayList<String> userNameFromFB;
ArrayList<String> userPhoneFromFB;
FirebaseDatabase firebaseDatabase;
DatabaseReference myRef;
private FirebaseAuth mAuth;
private StorageReference mStorageRef;
Uri selected;
profile_info adapter;
ListView listView;

EditText userName;
EditText userEmail;
EditText userPhone;
ImageView userImage;


@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_profile);

    userName = findViewById(R.id.nameText);
    userEmail = findViewById(R.id.emailText);
    userPhone = findViewById(R.id.phoneText);
    userImage = findViewById(R.id.profilePhoto);

    firebaseDatabase = FirebaseDatabase.getInstance();
    myRef = firebaseDatabase.getReference();
    mAuth= FirebaseAuth.getInstance();
    mStorageRef = FirebaseStorage.getInstance().getReference();

    userEmailFromFB = new ArrayList<>();
    userImageFromFB = new ArrayList<>();
    userNameFromFB = new ArrayList<>();
    userPhoneFromFB = new ArrayList<>();



    adapter = new profile_info(userImageFromFB,userNameFromFB,userEmailFromFB,userPhoneFromFB,this);
    listView = findViewById(R.id.listView);
    listView.setAdapter(adapter);

    getDataFromFirebase();


}

public void save (View view){

    UUID uuidImage1 = UUID.randomUUID();
    String imageName ="profilePhoto/"+uuidImage1+".jpg";

    StorageReference storageReference1 = mStorageRef.child(imageName);
    storageReference1.putFile(selected).addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
        @Override
        public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {

            String downloadURLL = taskSnapshot.getDownloadUrl().toString();

            FirebaseUser user = mAuth.getCurrentUser();
            String userEmail2 = user.getEmail().toString();
            String userName2 = userName.getText().toString();
            String userPhone2  = userPhone.getText().toString();

            UUID uuid1=UUID.randomUUID();
            String uudString1 =uuid1.toString();

            myRef.child("Profile").child("useremail").setValue(userEmail2);
            myRef.child("Profile").child("username").setValue(userName2);
            myRef.child("Profile").child("phone").setValue(userPhone2);
            myRef.child("Profile").child("downloadurl").setValue(downloadURLL);

            Toast.makeText(Profile.this, "İnformation Saved", Toast.LENGTH_SHORT).show();
        }
    }).addOnFailureListener(new OnFailureListener() {
        @Override
        public void onFailure(@NonNull Exception e) {
            Toast.makeText(Profile.this, e.getLocalizedMessage(), Toast.LENGTH_SHORT).show();
        }
    });
}

public void  getDataFromFirebase() {

    DatabaseReference newReference = firebaseDatabase.getReference("Profile");
    newReference.addValueEventListener(new ValueEventListener() {
        @Override
        public void onDataChange(DataSnapshot dataSnapshot) {
            for (DataSnapshot ds : dataSnapshot.getChildren()){

                HashMap<String,String> hashMap = (HashMap<String,String>) ds.getValue();
                userImageFromFB.add(hashMap.get("downloadurl"));
                userEmailFromFB.add(hashMap.get("useremail"));
                userNameFromFB.add(hashMap.get("username"));
                userPhoneFromFB.add(hashMap.get("phone"));
                adapter.notifyDataSetChanged();

            }
        }

        @Override
        public void onCancelled(DatabaseError databaseError) {

        }
    });
  }

@RequiresApi(api = Build.VERSION_CODES.M)
public  void chooseImage(View view){

    if(checkSelfPermission(android.Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED){
        requestPermissions(new String[] {android.Manifest.permission.READ_EXTERNAL_STORAGE},1);

    }else{
        Intent intent = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
        startActivityForResult(intent,2);
    }

}


@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {

    if(requestCode == 1){
        if(grantResults.length>0 && grantResults[0] == PackageManager.PERMISSION_GRANTED){
            Intent intent = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
            startActivityForResult(intent,2);
        }
    }

    super.onRequestPermissionsResult(requestCode, permissions, grantResults);
}
}

0 个答案:

没有答案