NullPointerException on setContentView - android

I am having two layouts in same xml file and I have kept one layout as hidden and want to show this hidden layout on button click. But when I try to load this activity, it gives me exception on setContentView.
Here is my layout:
<androidx.drawerlayout.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/drawer1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentStart="true"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#f0f5f9"
tools:context="com.techsof.demoapp.Auftrag">
<LinearLayout
android:id="#+id/header"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:background="#drawable/round_corners"
android:orientation="vertical"
android:padding="10dp">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fontFamily="serif"
android:gravity="center"
android:text="#string/heading"
android:textColor="#fff"
android:textSize="20sp"
android:textStyle="bold" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:fontFamily="serif"
android:gravity="center"
android:text="#string/heading_text"
android:textColor="#fff"
android:textSize="15sp" />
</LinearLayout>
<TextView
android:id="#+id/form_heading"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/header"
android:fontFamily="serif"
android:gravity="center"
android:text="#string/form_heading"
android:textColor="#4C4C4C"
android:textSize="20sp" />
<LinearLayout
android:id="#+id/form"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/form_heading"
android:layout_margin="10dp"
android:orientation="vertical">
<EditText
android:id="#+id/name"
android:layout_width="match_parent"
android:layout_height="50dp"
android:background="#drawable/input_fields"
android:fontFamily="serif"
android:hint="#string/name"
android:padding="10dp" />
<EditText
android:id="#+id/mail"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_marginTop="10dp"
android:background="#drawable/input_fields"
android:fontFamily="serif"
android:hint="#string/mail_"
android:padding="10dp" />
<EditText
android:id="#+id/tel"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_marginTop="10dp"
android:background="#drawable/input_fields"
android:fontFamily="serif"
android:hint="Tel/Mobilnummer *"
android:padding="10dp" />
<EditText
android:id="#+id/aus"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_marginTop="10dp"
android:background="#drawable/input_fields"
android:fontFamily="serif"
android:hint="Ausgangssprache *"
android:padding="10dp" />
<EditText
android:id="#+id/ziel"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_marginTop="10dp"
android:background="#drawable/input_fields"
android:fontFamily="serif"
android:hint="Zielsprache *"
android:padding="10dp" />
<EditText
android:id="#+id/nach"
android:layout_width="match_parent"
android:layout_height="100dp"
android:layout_marginTop="10dp"
android:background="#drawable/input_fields"
android:fontFamily="serif"
android:gravity="start"
android:hint="Nachricht *"
android:padding="10dp" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:orientation="horizontal">
<TextView
android:id="#+id/doc1"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_weight="1"
android:background="#drawable/odd_corners"
android:fontFamily="serif"
android:gravity="start"
android:padding="10dp" />
<Button
android:id="#+id/attach_btn1"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_weight="1.5"
android:background="#drawable/odd_corners_btn"
android:drawableStart="#drawable/ic_file_upload_black_24dp"
android:drawableLeft="#drawable/ic_file_upload_black_24dp"
android:text="#string/doc1"
android:textAllCaps="false"
android:textColor="#fff" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:orientation="horizontal">
<TextView
android:id="#+id/doc2"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_weight="1"
android:background="#drawable/odd_corners"
android:fontFamily="serif"
android:gravity="start"
android:padding="10dp" />
<Button
android:id="#+id/attach_btn2"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_weight="1.5"
android:background="#drawable/odd_corners_btn"
android:drawableStart="#drawable/ic_file_upload_black_24dp"
android:drawableLeft="#drawable/ic_file_upload_black_24dp"
android:text="#string/doc2"
android:textAllCaps="false"
android:textColor="#fff" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:orientation="horizontal">
<TextView
android:id="#+id/doc3"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_weight="1"
android:background="#drawable/odd_corners"
android:fontFamily="serif"
android:gravity="start"
android:padding="10dp" />
<Button
android:id="#+id/attach_btn3"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_weight="1.5"
android:background="#drawable/odd_corners_btn"
android:drawableStart="#drawable/ic_file_upload_black_24dp"
android:drawableLeft="#drawable/ic_file_upload_black_24dp"
android:text="#string/doc3"
android:textAllCaps="false"
android:textColor="#fff" />
</LinearLayout>
</LinearLayout>
<TextView
android:id="#+id/footer_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/form"
android:layout_margin="10dp"
android:fontFamily="serif"
android:gravity="center"
android:text="#string/footer_text"
android:textColor="#4C4C4C"
android:textSize="12sp"
android:textStyle="bold" />
<CheckBox
android:id="#+id/checkbox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/footer_text"
android:layout_marginLeft="10dp"
android:buttonTint="#0F84AA"
android:fontFamily="serif"
android:text="#string/checkbox_text"
android:textColor="#4c4c4c"
android:textStyle="bold" />
<Button
android:id="#+id/sendBtn"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/checkbox"
android:layout_margin="10dp"
android:background="#drawable/round_corners"
android:text="#string/button_text"
android:textAllCaps="false"
android:textColor="#fff" />
</RelativeLayout>
</ScrollView>
<LinearLayout
android:id="#+id/dialogBox"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="30dp"
android:layout_marginRight="30dp"
android:gravity="center"
android:orientation="vertical"
android:visibility="gone">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#4c4c4c"
android:padding="10dp"
android:text="#string/complete_action_using"
android:textColor="#fff"
android:textSize="20sp" />
<view
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#fff" />
<LinearLayout
android:id="#+id/cameraOption"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#CDCDCD"
android:orientation="horizontal">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:padding="10dp"
android:src="#drawable/ic_camera_alt_black_24dp" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="#string/camera"
android:textColor="#fff"
android:textSize="18sp" />
</LinearLayout>
<view
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#fff" />
<LinearLayout
android:id="#+id/phoneStorageOption"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#CDCDCD"
android:orientation="horizontal">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:padding="10dp"
android:src="#drawable/ic_folder_open_black_24dp" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="#string/phone_storage"
android:textColor="#fff"
android:textSize="18sp" />
</LinearLayout>
<view
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#fff" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#CDCDCD"
android:gravity="end"
android:padding="10dp">
<Button
android:id="#+id/cancelBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="10dp"
android:layout_marginRight="10dp"
android:backgroundTint="#0F84AA"
android:text="#string/cancel"
android:textColor="#fff" />
</LinearLayout>
</LinearLayout>
<com.google.android.material.navigation.NavigationView
android:id="#+id/navigation1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="start"
android:background="#f0f5f9"
app:headerLayout="#layout/nav_header"
app:itemIconTint="#000"
app:itemTextColor="#000"
app:menu="#menu/menu_main" />
</androidx.drawerlayout.widget.DrawerLayout>
and here is my Java Code:
public class Auftrag extends AppCompatActivity implements NavigationView.OnNavigationItemSelectedListener {
private DrawerLayout eDrawerlayout;
private ActionBarDrawerToggle eToggle;
NavigationView nav;
private LinearLayout camera, phone, dialog;
private Button attachBtn1, attachBtn2, attachBtn3, submitButton, cancel;
private TextView file1, file2, file3;
private EditText name, mail, telephone, ausgang, ziels, nachricht;
private ArrayList<Uri> attachments = new ArrayList<>();
private CheckBox agreement;
private String textfield;
public static final int REQUEST_SELECT_FILE = 100;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.form);
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);
initUI();
eToggle = new ActionBarDrawerToggle(this, eDrawerlayout, R.string.Open, R.string.Close);
eDrawerlayout.addDrawerListener(eToggle);
eToggle.syncState();
nav.setNavigationItemSelectedListener(this);
androidx.appcompat.app.ActionBar actionBar = getSupportActionBar();
assert actionBar != null;
actionBar.setBackgroundDrawable(new ColorDrawable(android.graphics.Color.parseColor("#f0f5f9")));
eDrawerlayout.setDrawerListener(eToggle);
actionBar.setDisplayHomeAsUpEnabled(true);
actionBar.setDisplayShowTitleEnabled(true);
}
private void initUI() {
nav = findViewById(R.id.navigation1);
eDrawerlayout = findViewById(R.id.drawer1);
name = findViewById(R.id.name);
mail = findViewById(R.id.mail);
telephone = findViewById(R.id.tel);
ausgang = findViewById(R.id.aus);
ziels = findViewById(R.id.ziel);
nachricht = findViewById(R.id.nach);
submitButton = findViewById(R.id.sendBtn);
attachBtn1 = findViewById(R.id.attach_btn1);
attachBtn2 = findViewById(R.id.attach_btn2);
attachBtn3 = findViewById(R.id.attach_btn3);
/*dialog = findViewById(R.id.dialogBox);
camera = findViewById(R.id.cameraOption);
camera.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
openCamera();
}
});
phone = findViewById(R.id.phoneStorageOption);
phone.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
openFileChooser();
}
});
cancel = findViewById(R.id.cancelBtn);
cancel.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
dialog.setVisibility(View.GONE);
}
});*/
file1 = findViewById(R.id.doc1);
file2 = findViewById(R.id.doc2);
file3 = findViewById(R.id.doc3);
attachBtn1.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
textfield = "btn1";
chooseOption();
/*dialog.setVisibility(View.VISIBLE);*/
}
});
attachBtn2.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
textfield = "btn2";
/*dialog.setVisibility(View.VISIBLE);*/
}
});
attachBtn3.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
textfield = "btn3";
/*dialog.setVisibility(View.VISIBLE);*/
}
});
agreement = findViewById(R.id.checkbox);
submitButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
sendData();
}
});
}
private void chooseOption() {
final CharSequence[] options = {"Camera", "Phone", "Cancel"};
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("Add file using: ");
builder.setItems(options, new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int item) {
if (options[item].equals("Camera")) {
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
File f = new File(android.os.Environment.getExternalStorageDirectory(), "temp.jpg");
intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(f));
startActivityForResult(intent, 1);
} else if (options[item].equals("Phone")) {
openFileChooser();
} else if (options[item].equals("Cancel")) {
dialog.dismiss();
}
}
});
builder.show();
}
private void openFileChooser() {
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.addCategory(Intent.CATEGORY_OPENABLE);
intent.setType("*/*");
startActivityForResult(intent, REQUEST_SELECT_FILE);
}
private void sendData() {
if (TextUtils.isEmpty(name.getText()) || TextUtils.isEmpty(mail.getText()) ||
TextUtils.isEmpty(telephone.getText()) || TextUtils.isEmpty(ausgang.getText())
|| TextUtils.isEmpty(ziels.getText()) || TextUtils.isEmpty(nachricht.getText())
|| TextUtils.isEmpty(file1.getText()) || TextUtils.isEmpty(file3.getText()) ||
TextUtils.isEmpty(file3.getText())) {
Toast.makeText(this, "Please fill out all fields.", Toast.LENGTH_SHORT).show();
} else {
if (agreement.isChecked()) {
if (isConnected()) {
ArrayList<String> data = new ArrayList<>();
data.add(name.getText().toString());
data.add(mail.getText().toString());
data.add(telephone.getText().toString());
data.add(ausgang.getText().toString());
data.add(ziels.getText().toString());
data.add(nachricht.getText().toString());
new SendMailTask(this).execute("metaphrase.online#gmail.com", "Admintogether-2000222",
"salman.footy.k7#gmail.com", "User Information", data.get(0), data.get(1),
data.get(2), data.get(3), data.get(4), data.get(5), getFullPath(attachments.get(0)),
getFullPath(attachments.get(1)), getFullPath(attachments.get(2)));
} else {
Toast.makeText(this, "Please check your internet connection and try again.", Toast.LENGTH_SHORT).show();
}
} else {
Toast.makeText(this, "Please select the checkbox.", Toast.LENGTH_SHORT).show();
}
}
}
public boolean onOptionsItemSelected(#NonNull MenuItem item) {
if (eToggle.onOptionsItemSelected(item)) {
}
return true;
}
public boolean onNavigationItemSelected(#NonNull MenuItem item) {
int id = item.getItemId();
switch (id) {
case R.id.home:
startActivity(new Intent(Auftrag.this, MainActivity.class));
break;
case R.id.web:
Intent browser = new Intent(Intent.ACTION_VIEW, Uri.parse("https://metaphrase.online"));
startActivity(browser);
break;
case R.id.help:
startActivity(new Intent(Auftrag.this, Feedback.class));
break;
case R.id.upload:
if (isConnected()) {
startActivity(new Intent(Auftrag.this, Auftrag.class));
} else {
Toast.makeText(this, "Bitte überprüfen Sie Ihre Internetverbindung!", Toast.LENGTH_SHORT)
.show();
}
break;
}
eDrawerlayout.closeDrawer(GravityCompat.START);
return true;
}
#Override
public void onActivityResult(int requestCode, int resultCode, Intent intent) {
if (requestCode != REQUEST_SELECT_FILE || resultCode != RESULT_OK) {
Toast.makeText(this, "No file selected.", Toast.LENGTH_SHORT).show();
dialog.setVisibility(View.GONE);
} else {
importFile(intent);
}
}
private void importFile(Intent intent) {
if (intent != null) {
String fileName = getFileName(intent.getData());
if (textfield != null) {
if (textfield.equals("btn1")) {
dialog.setVisibility(View.GONE);
file1.setText(fileName);
attachments.add(intent.getData());
} else if (textfield.equals("btn2")) {
dialog.setVisibility(View.GONE);
file2.setText(fileName);
attachments.add(intent.getData());
} else {
dialog.setVisibility(View.GONE);
file3.setText(fileName);
attachments.add(intent.getData());
}
} else {
Toast.makeText(this, "Try again later.", Toast.LENGTH_SHORT).show();
}
}
}
private String getFullPath(Uri fileUri) {
String filePath = null;
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) {
try {
filePath = PathUtil.getPath(this, fileUri);
} catch (URISyntaxException e) {
e.printStackTrace();
}
} else {
File file = new File(fileUri.getPath());
final String[] split = file.getPath().split(":");
filePath = split[1];
}
return filePath;
}
private String getFileName(Uri data) {
Cursor cursor = getContentResolver().query(data, null, null, null, null);
if (cursor.getCount() <= 0) {
cursor.close();
throw new IllegalArgumentException("Can't obtain file name, cursor is empty");
}
cursor.moveToFirst();
String fileName = cursor.getString(cursor.getColumnIndexOrThrow(OpenableColumns.DISPLAY_NAME));
cursor.close();
return fileName;
}
public boolean isConnected() {
boolean connected = false;
try {
ConnectivityManager cm = (ConnectivityManager) getApplicationContext().getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo nInfo = cm.getActiveNetworkInfo();
connected = nInfo != null && nInfo.isAvailable() && nInfo.isConnected();
return connected;
} catch (Exception e) {
Log.e("Connectivity Exception", e.getMessage());
}
return connected;
}
}

So the problem should be in the <view ../> tag, the correct form is <View ... />. You should change your XML file with the following:
<androidx.drawerlayout.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/drawer1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentStart="true"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#f0f5f9"
tools:context="com.techsof.demoapp.Auftrag">
<LinearLayout
android:id="#+id/header"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:background="#drawable/round_corners"
android:orientation="vertical"
android:padding="10dp">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fontFamily="serif"
android:gravity="center"
android:text="#string/heading"
android:textColor="#fff"
android:textSize="20sp"
android:textStyle="bold" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:fontFamily="serif"
android:gravity="center"
android:text="#string/heading_text"
android:textColor="#fff"
android:textSize="15sp" />
</LinearLayout>
<TextView
android:id="#+id/form_heading"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/header"
android:fontFamily="serif"
android:gravity="center"
android:text="#string/form_heading"
android:textColor="#4C4C4C"
android:textSize="20sp" />
<LinearLayout
android:id="#+id/form"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/form_heading"
android:layout_margin="10dp"
android:orientation="vertical">
<EditText
android:id="#+id/name"
android:layout_width="match_parent"
android:layout_height="50dp"
android:background="#drawable/input_fields"
android:fontFamily="serif"
android:hint="#string/name"
android:padding="10dp" />
<EditText
android:id="#+id/mail"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_marginTop="10dp"
android:background="#drawable/input_fields"
android:fontFamily="serif"
android:hint="#string/mail_"
android:padding="10dp" />
<EditText
android:id="#+id/tel"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_marginTop="10dp"
android:background="#drawable/input_fields"
android:fontFamily="serif"
android:hint="Tel/Mobilnummer *"
android:padding="10dp" />
<EditText
android:id="#+id/aus"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_marginTop="10dp"
android:background="#drawable/input_fields"
android:fontFamily="serif"
android:hint="Ausgangssprache *"
android:padding="10dp" />
<EditText
android:id="#+id/ziel"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_marginTop="10dp"
android:background="#drawable/input_fields"
android:fontFamily="serif"
android:hint="Zielsprache *"
android:padding="10dp" />
<EditText
android:id="#+id/nach"
android:layout_width="match_parent"
android:layout_height="100dp"
android:layout_marginTop="10dp"
android:background="#drawable/input_fields"
android:fontFamily="serif"
android:gravity="start"
android:hint="Nachricht *"
android:padding="10dp" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:orientation="horizontal">
<TextView
android:id="#+id/doc1"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_weight="1"
android:background="#drawable/odd_corners"
android:fontFamily="serif"
android:gravity="start"
android:padding="10dp" />
<Button
android:id="#+id/attach_btn1"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_weight="1.5"
android:background="#drawable/odd_corners_btn"
android:drawableStart="#drawable/ic_file_upload_black_24dp"
android:drawableLeft="#drawable/ic_file_upload_black_24dp"
android:text="#string/doc1"
android:textAllCaps="false"
android:textColor="#fff" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:orientation="horizontal">
<TextView
android:id="#+id/doc2"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_weight="1"
android:background="#drawable/odd_corners"
android:fontFamily="serif"
android:gravity="start"
android:padding="10dp" />
<Button
android:id="#+id/attach_btn2"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_weight="1.5"
android:background="#drawable/odd_corners_btn"
android:drawableStart="#drawable/ic_file_upload_black_24dp"
android:drawableLeft="#drawable/ic_file_upload_black_24dp"
android:text="#string/doc2"
android:textAllCaps="false"
android:textColor="#fff" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:orientation="horizontal">
<TextView
android:id="#+id/doc3"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_weight="1"
android:background="#drawable/odd_corners"
android:fontFamily="serif"
android:gravity="start"
android:padding="10dp" />
<Button
android:id="#+id/attach_btn3"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_weight="1.5"
android:background="#drawable/odd_corners_btn"
android:drawableStart="#drawable/ic_file_upload_black_24dp"
android:drawableLeft="#drawable/ic_file_upload_black_24dp"
android:text="#string/doc3"
android:textAllCaps="false"
android:textColor="#fff" />
</LinearLayout>
</LinearLayout>
<TextView
android:id="#+id/footer_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/form"
android:layout_margin="10dp"
android:fontFamily="serif"
android:gravity="center"
android:text="#string/footer_text"
android:textColor="#4C4C4C"
android:textSize="12sp"
android:textStyle="bold" />
<CheckBox
android:id="#+id/checkbox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/footer_text"
android:layout_marginLeft="10dp"
android:buttonTint="#0F84AA"
android:fontFamily="serif"
android:text="#string/checkbox_text"
android:textColor="#4c4c4c"
android:textStyle="bold" />
<Button
android:id="#+id/sendBtn"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/checkbox"
android:layout_margin="10dp"
android:background="#drawable/round_corners"
android:text="#string/button_text"
android:textAllCaps="false"
android:textColor="#fff" />
</RelativeLayout>
</ScrollView>
<LinearLayout
android:id="#+id/dialogBox"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="30dp"
android:layout_marginRight="30dp"
android:gravity="center"
android:orientation="vertical"
android:visibility="gone">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#4c4c4c"
android:padding="10dp"
android:text="#string/complete_action_using"
android:textColor="#fff"
android:textSize="20sp" />
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#fff" />
<LinearLayout
android:id="#+id/cameraOption"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#CDCDCD"
android:orientation="horizontal">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:padding="10dp"
android:src="#drawable/ic_camera_alt_black_24dp" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="#string/camera"
android:textColor="#fff"
android:textSize="18sp" />
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#fff" />
<LinearLayout
android:id="#+id/phoneStorageOption"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#CDCDCD"
android:orientation="horizontal">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:padding="10dp"
android:src="#drawable/ic_folder_open_black_24dp" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="#string/phone_storage"
android:textColor="#fff"
android:textSize="18sp" />
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#fff" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#CDCDCD"
android:gravity="end"
android:padding="10dp">
<Button
android:id="#+id/cancelBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="10dp"
android:layout_marginRight="10dp"
android:backgroundTint="#0F84AA"
android:text="#string/cancel"
android:textColor="#fff" />
</LinearLayout>
</LinearLayout>
<com.google.android.material.navigation.NavigationView
android:id="#+id/navigation1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="start"
android:background="#f0f5f9"
app:headerLayout="#layout/nav_header"
app:itemIconTint="#000"
app:itemTextColor="#000"
app:menu="#menu/menu_main" />
</androidx.drawerlayout.widget.DrawerLayout>

Related

Clicking on navigation drawer listview item opens unclicked activity every time

I'm implementing a service and receiver in SettingsActivity and when i open the app for the first time there is no issue but once I visit SettingsActivity and come back, closing the navigation drawer from then on opens SettingsActivity everytime even if don't click any item in the listview
This is my MainActivity layout file where i have implemented navigation drawer :-
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
android:orientation="vertical"
android:fitsSystemWindows="true"
android:id="#+id/drawer_layout">
<FrameLayout
android:id="#+id/main"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:baselineAligned="false"
android:orientation="vertical">
<LinearLayout
android:id="#+id/top_view"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.3"
android:background="#00AFF0"
android:orientation="vertical">
<TextView
android:id="#+id/ship_name"
android:layout_width="wrap_content"
android:minWidth="120dp"
android:layout_height="40dp"
android:layout_gravity="center"
android:gravity="center"
android:textColor="#00AFF0"
android:background="#drawable/button_background"
android:padding="10dp"
android:textSize="16sp"
/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_gravity="center"
android:gravity="center"
android:layout_marginTop="10dp">
<ImageButton
android:id="#+id/date_reset"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_action_reset"
android:background="#android:color/transparent"
android:layout_marginEnd="10dp"
android:visibility="gone"/>
<TextView
android:id="#+id/current_date"
android:layout_width="wrap_content"
android:minWidth="120dp"
android:layout_height="40dp"
android:layout_gravity="center"
android:gravity="center"
android:textColor="#android:color/white"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp"
android:textSize="16sp"
/>
<ImageButton
android:id="#+id/date_select"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_action_date"
android:background="#android:color/transparent"
android:layout_marginStart="10dp"/>
</LinearLayout>
<LinearLayout
android:id="#+id/tickets_layout"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_marginTop="10dp"
android:layout_gravity="center"
android:layout_marginEnd="20dp"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_marginStart="20dp"
android:background="#drawable/button_border"
android:gravity="center"
android:minWidth="120dp"
android:orientation="horizontal"
android:textColor="#android:color/white">
<TextView
android:id="#+id/ticket_no_count"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="0.2"
android:gravity="end|center"
android:padding="2dp"
android:text=""
android:textColor="#FFFF00"
android:textSize="16sp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="0.2"
android:padding="2dp"
android:gravity="center_vertical"
android:text="#string/tickets"
android:textAllCaps="true"
android:textColor="#android:color/white"
android:textSize="16sp" />
<View
android:layout_width="2dp"
android:layout_height="match_parent"
android:background="#android:color/white" />
<TextView
android:id="#+id/no_of_people_count"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="0.2"
android:gravity="end|center"
android:padding="2dp"
android:textSize="16sp"
android:textColor="#FFFF00" />
<TextView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="0.2"
android:padding="2dp"
android:text="#string/people"
android:textSize="16sp"
android:textAllCaps="true"
android:gravity="center_vertical"
android:textColor="#android:color/white" />
</LinearLayout>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/txt_no_data"
android:gravity="center|center_horizontal"
android:textSize="18sp"
android:textColor="#color/textColor"
android:textStyle="bold"
android:visibility="gone"
android:paddingTop="15dp"
/>
</LinearLayout>
<LinearLayout
android:id="#+id/search_layout"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.2"
android:orientation="vertical"
android:layout_gravity="center">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="10dp">
<EditText
android:id="#+id/ticket_no"
android:layout_width="0dp"
android:layout_height="40dp"
android:layout_weight="0.8"
android:layout_marginStart="20dp"
android:layout_marginRight="5dp"
android:layout_marginEnd="5dp"
android:background="#drawable/edittextbackground"
android:imeOptions="actionDone"
android:paddingStart="10dp"
android:paddingEnd="0dp"
android:maxLength="19"
android:inputType="number"
android:digits="01234 56789"
android:maxLines="1"
/>
<Button
android:id="#+id/search_ticket_button"
android:layout_width="0dp"
android:layout_height="40dp"
android:layout_marginEnd="20dp"
android:layout_weight="0.2"
android:textColor="#android:color/white"
android:text="#string/go"
android:textSize="16sp"
android:textAllCaps="true"
android:background="#drawable/go_button_shape"/>
</LinearLayout>
<LinearLayout
android:id="#+id/or_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="30dp"
android:orientation="horizontal"
android:paddingRight="30dp">
<View
android:layout_width="0dp"
android:layout_height="2dp"
android:layout_weight="0.4"
android:layout_gravity="center_vertical"
android:background="#android:color/black"
/>
<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.1"
android:text="#string/or"
android:textSize="20sp"
android:gravity="center"/>
<View
android:layout_width="0dp"
android:layout_height="2dp"
android:layout_weight="0.4"
android:layout_gravity="center_vertical"
android:background="#android:color/black"
/>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:id="#+id/scan_layout"
android:layout_width="match_parent"
android:layout_height="0dp"
android:orientation="vertical"
android:layout_weight="0.5">
<Button
android:id="#+id/scanQr"
android:layout_width="wrap_content"
android:minWidth="120dp"
android:layout_height="40dp"
android:text="#string/scan_qr"
android:layout_gravity="center|top"
android:gravity="center"
android:textColor="#android:color/white"
android:background="#drawable/scan_button"
android:padding="10dp"
android:layout_marginTop="10dp"
android:textSize="16sp"
/>
<me.dm7.barcodescanner.zxing.ZXingScannerView
android:id="#+id/scanner"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"/>
<TextView
android:id="#+id/scan_results"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:layout_marginTop="50dp"
android:layout_marginBottom="10dp"
android:visibility="visible"
android:textStyle="bold"
android:textSize="18sp"
android:gravity="left"
android:layout_marginStart="20dp"
android:layout_marginRight="5dp"
android:layout_marginEnd="5dp"
android:paddingStart="10dp"
android:paddingEnd="0dp"
/>
</LinearLayout>
<TextView
android:id="#+id/no_trips_tv"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.5"
android:layout_gravity="center"
android:gravity="center"
android:textColor="#android:color/darker_gray"
android:textSize="18sp"
android:text="#string/no_trips"
android:visibility="gone"/>
</LinearLayout>
</FrameLayout>
<FrameLayout
android:id="#+id/layout_layer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#android:color/transparent"
android:alpha="0.5"
/>
<ListView
android:id="#+id/drawer"
android:layout_width="240dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:background="#FFF"
android:choiceMode="singleChoice"
/>
</android.support.v4.widget.DrawerLayout>
And in my MainActivity i handle item click events like this where navList is Listview and drawer is DrawerLayout :-
navList.setOnItemClickListener(new AdapterView.OnItemClickListener(){
#Override
public void onItemClick(AdapterView<?> parent, View view, final int position, long id){
drawer.setDrawerListener( new DrawerLayout.SimpleDrawerListener(){
#Override
public void onDrawerClosed(View drawerView){
super.onDrawerClosed(drawerView);
if (position == 0){
} else if(position == 1)
{
getTicketsInfo(Helper.getValueFromSharedPreferences("shipId",getApplicationContext()),currentDate);
} else if(position == 2) {
submitTickets();
} else if(position == 3) {
Intent settingsIntent = new Intent(MainActivity.this, SettingsActivity.class);
startActivity(settingsIntent);
} else {
Helper.removeKeyStoredinSharedPreferences("sessionHandle", getApplicationContext());
finish();
}
}
});
drawer.closeDrawer(navList);
}
});
remove drawer.setDrawerListener and place the code directly inside onItemClick
drawerList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
switch(position)
{
case:0
{
break;
}
case:1
{
getTicketsInfo(Helper.getValueFromSharedPreferences("shipId",getApplicationContext()),currentDate);
break;
}
case:2
{
submitTickets();
break;
}
case:3
{
Intent settingsIntent = new Intent(MainActivity.this, SettingsActivity.class);
startActivity(settingsIntent);
break;
}
case:4{
Helper.removeKeyStoredinSharedPreferences("sessionHandle", getApplicationContext());
finish();
break;
}
default:
}
}
});
drawer.closeDrawer(navList);
}

I am getting ANR , when i click on Edittext for texting

I am getting ANR , when i click on Edittext for texting and My logcat giving msg:- Reason: Input dispatching timed out (Waiting to send key event because the focused window has not finished processing all of the input events that were previously delivered to it. Outbound queue length: 0. Wait queue length: 1.)
edit_personal_details.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
edit_personal_details.setVisibility(View.INVISIBLE);
edit_personal_details_save.setVisibility(View.VISIBLE);
email_et.setFocusable(true);
website_et.setFocusable(true);
twitter_id_et.setFocusable(true);
email_et.setFocusableInTouchMode(true);
website_et.setFocusableInTouchMode(true);
twitter_id_et.setFocusableInTouchMode(true);
email_et.setEnabled(true);
website_et.setEnabled(true);
twitter_id_et.setEnabled(true);
}
});
edit_personal_details_save.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
edit_personal_details_save.setVisibility(View.INVISIBLE);
edit_personal_details.setVisibility(View.VISIBLE);
dob_et.setFocusableInTouchMode(false);
email_et.setFocusableInTouchMode(false);
website_et.setFocusableInTouchMode(false);
twitter_id_et.setFocusableInTouchMode(false);
email_et.setEnabled(false);
website_et.setEnabled(false);
twitter_id_et.setEnabled(false);
email_et.setFocusable(false);
website_et.setFocusable(false);
twitter_id_et.setFocusable(false);
dob_et_str = dob_et.getText().toString();
email_et_str = email_et.getText().toString();
website_et_str = website_et.getText().toString();
twitter_id_et_str = twitter_id_et.getText().toString();
AddPersonalDetails addPersonalDetails = new AddPersonalDetails();
addPersonalDetails.execute();
}
});
......................AddPersonalDetails Class..................................
private class AddPersonalDetails extends AsyncTask<String, Void, Void> {
ProgressDialog progressDialog;
String ResponseFromAddPersonalDetails;
#Override
protected Void doInBackground(String... params) {
//Invoke webservice
profile_sharedPreferences = getActivity().getSharedPreferences(SHARED_PREF, MODE_PRIVATE);
String Userid = profile_sharedPreferences.getString("userId", null);
WebService wsc = new WebService();
ResponseFromAddPersonalDetails = wsc.AddPersonalDetails(Userid, dob_et_str, email_et_str, website_et_str, "skype", twitter_id_et_str, serviceToken, "AddPersonalDetails");
return null;
}
#Override
protected void onPostExecute(Void result) {
//Set response
try {
} catch (Exception e) {
e.printStackTrace();
}
progressDialog.dismiss();
}
#Override
protected void onPreExecute() {
//Make ProgressBar invisible
progressDialog = new ProgressDialog(getActivity());
progressDialog.setMessage("Loading, please wait.......");
progressDialog.show();
}
#Override
protected void onProgressUpdate(Void... values) {
}
}
...........................Xml Code............................................
<LinearLayout
android:id="#+id/mLinearPersonalDetails"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/linearLayout"
android:layout_marginTop="7dp"
android:background="#drawable/rounded_layout"
android:fitsSystemWindows="true"
android:orientation="vertical">
<RelativeLayout
android:id="#+id/relativeLayout6"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingLeft="10dp"
android:paddingRight="10dp">
<TextView
android:id="#+id/social_heading"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_centerVertical="true"
android:layout_marginLeft="5dp"
android:text="Personal Details"
android:textColor="#color/profile_name_txt"
android:textSize="15sp"
android:textStyle="bold" />
<Button
android:id="#+id/edit_personal_details_save"
android:layout_width="70dp"
android:layout_height="20dp"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:background="#drawable/buttonshape"
android:text="save"
android:textColor="#color/layout_profile"
android:visibility="invisible" />
<ImageButton
android:id="#+id/edit_personal_details"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginBottom="7dp"
android:background="#color/layout_profile"
android:scaleType="centerCrop"
android:src="#mipmap/edit_user_name"
android:windowSoftInputMode="stateHidden|adjustResize|adjustPan" />
<View
android:id="#+id/viewbreaker9"
android:layout_width="wrap_content"
android:layout_height="2dp"
android:layout_alignParentBottom="true"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_marginBottom="35dp"
android:background="#e4e4e4" />
</RelativeLayout>
<LinearLayout
android:id="#+id/linearlayout13"
android:layout_width="match_parent"
android:layout_height="55dp"
android:layout_gravity="center_horizontal"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="5dp"
android:orientation="horizontal">
<ImageView
android:layout_width="35dp"
android:layout_height="35dp"
android:src="#mipmap/birthday" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="15dp"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Birthday"
android:textSize="12sp"
android:textStyle="bold" />
<TextView
android:id="#+id/dob_et"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:backgroundTint="#color/layout_profile"
android:focusable="false"
android:text="September 13"
android:textColor="#color/profile_name_txt"
android:textSize="12sp" />
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginTop="5dp"
android:background="#e4e4e4" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:id="#+id/linearlayout14"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:orientation="horizontal">
<ImageView
android:layout_width="35dp"
android:layout_height="35dp"
android:src="#mipmap/email" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="15dp"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingLeft="3dp"
android:text="Email"
android:textSize="12sp"
android:textStyle="bold" />
<EditText
android:id="#+id/email_et"
android:layout_width="fill_parent"
android:layout_height="35dp"
android:backgroundTint="#color/layout_profile"
android:inputType="text|textNoSuggestions"
android:maxLines="1"
android:paddingBottom="1dp"
android:paddingTop="1dp"
android:text="myemail#email.com"
android:textColor="#color/profile_name_txt"
android:textSize="12sp" />
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#e4e4e4" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:id="#+id/linearlayout_website"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:orientation="horizontal">
<ImageView
android:layout_width="35dp"
android:layout_height="35dp"
android:layout_marginTop="5dp"
android:src="#mipmap/website" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="15dp"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:paddingLeft="3dp"
android:text="Website"
android:textSize="12sp"
android:textStyle="bold" />
<EditText
android:id="#+id/website_et"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:backgroundTint="#color/layout_profile"
android:focusable="false"
android:inputType="text|textNoSuggestions"
android:maxLines="1"
android:paddingBottom="1dp"
android:paddingTop="1dp"
android:text="www.Iparun.com"
android:textColor="#color/profile_name_txt"
android:textSize="12sp"
android:windowSoftInputMode="adjustResize" />
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#e4e4e4" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:id="#+id/linearlayout_twitter"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:orientation="horizontal">
<ImageView
android:layout_width="35dp"
android:layout_height="35dp"
android:layout_marginTop="5dp"
android:src="#mipmap/twitter" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="15dp"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:paddingLeft="3dp"
android:text="TWITTER"
android:textSize="12sp"
android:textStyle="bold" />
<EditText
android:id="#+id/twitter_id_et"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:backgroundTint="#color/layout_profile"
android:focusable="false"
android:inputType="text|textNoSuggestions"
android:maxLines="1"
android:paddingBottom="1dp"
android:paddingTop="1dp"
android:text="ip_arun"
android:textColor="#color/profile_name_txt"
android:textSize="12sp"
android:windowSoftInputMode="adjustResize" />
</LinearLayout>
</LinearLayout>
</LinearLayout>

Unexpected margin in bottom sheet after using SearchView

I am facing a strange issue working with SearchView and BottomSheet.
BottomSheet gets an unexpected margin when used after using SearchView. They video explains the problem.
Video
XML
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
<xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/main_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/backgroundcolor"
android:fitsSystemWindows="true">
<android.support.v7.widget.RecyclerView
android:id="#+id/trip_recyclerView"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<android.support.v4.widget.NestedScrollView
android:id="#+id/bottom_sheet"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/backgroundcolor"
android:clipToPadding="false"
app:layout_behavior="android.support.design.widget.BottomSheetBehavior">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="32dp"
android:orientation="vertical"
android:padding="12dp">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:text="Sort & Filter"
android:textColor="#color/black"
android:textSize="18sp"
android:textStyle="bold" />
<TextView
android:id="#+id/sheet_done"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:drawablePadding="8dp"
android:drawableStart="#drawable/ic_done"
android:text="Done"
android:textSize="18sp" />
</RelativeLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:text="Sort By" />
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<Spinner
android:id="#+id/sheet_spinner"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:entries="#array/sort_by"
android:padding="8dp" />
</LinearLayout>
</android.support.v7.widget.CardView>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:text="Price Range" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginEnd="12dp"
android:layout_marginStart="12dp"
android:layout_marginTop="8dp"
android:orientation="horizontal">
<TextView
android:id="#+id/sheet_price_min"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="#+id/sheet_price_max"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="end"
android:gravity="end" />
</LinearLayout>
<SeekBar
android:id="#+id/sheet_bar_price"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:thumb="?android:attr/textSelectHandle" />
<TextView
android:id="#+id/sheet_price_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:text="Rs 1,115" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:text="Ratings" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginEnd="12dp"
android:layout_marginStart="12dp"
android:layout_marginTop="8dp"
android:orientation="horizontal">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="1" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="12dp"
android:layout_weight="1"
android:gravity="start"
android:text="2" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:text="3" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginEnd="12dp"
android:layout_weight="1"
android:gravity="end"
android:text="4" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="end"
android:text="5" />
</LinearLayout>
<SeekBar
android:id="#+id/sheet_bar_rating"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:max="4"
android:thumb="?android:attr/textSelectHandle" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:text="Packages" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<CheckBox
android:id="#+id/sheet_package_gold"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="12dp"
android:layout_marginRight="12dp"
android:layout_weight="1"
android:text="Gold" />
<CheckBox
android:id="#+id/sheet_package_diamond"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="12dp"
android:layout_marginRight="12dp"
android:layout_weight="1"
android:text="Diamond" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<CheckBox
android:id="#+id/sheet_package_silver"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="12dp"
android:layout_marginRight="12dp"
android:layout_weight="1"
android:text="Silver" />
<CheckBox
android:id="#+id/sheet_package_platinum"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="12dp"
android:layout_marginRight="12dp"
android:layout_weight="1"
android:text="Platinum" />
</LinearLayout>
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
</android.support.design.widget.CoordinatorLayout>
Activity
public class TripsActivity extends AppCompatActivity implements
SearchView.OnQueryTextListener, SeekBar.OnSeekBarChangeListener, View.OnClickListener {
public String MAX = "150000";
public String MIN = "0";
#BindView(R.id.trip_recyclerView)
RecyclerView recyclerView;
#BindView(R.id.bottom_sheet)
View view;
#BindView(R.id.sheet_spinner)
Spinner spinner;
#BindView(R.id.sheet_price_min)
TextView minPrice;
#BindView(R.id.sheet_price_max)
TextView maxPrice;
#BindView(R.id.sheet_price_text)
TextView currentPrice;
#BindView(R.id.sheet_bar_price)
SeekBar priceBar;
#BindView(R.id.sheet_bar_rating)
SeekBar ratingBar;
#BindView(R.id.sheet_package_gold)
CheckBox packageGold;
#BindView(R.id.sheet_package_silver)
CheckBox packageSilver;
#BindView(R.id.sheet_package_platinum)
CheckBox packagePlatinum;
#BindView(R.id.sheet_package_diamond)
CheckBox packageDiamond;
BottomSheetBehavior.BottomSheetCallback callback = new BottomSheetBehavior.BottomSheetCallback() {
#Override
public void onStateChanged(#NonNull View bottomSheet, int newState) {
}
#Override
public void onSlide(#NonNull View bottomSheet, float slideOffset) {
if (slideOffset < 0.4)
getSupportActionBar().show();
else
getSupportActionBar().hide();
}
};
private SearchView searchView;
private TripsAdapter adapter;
private BottomSheetBehavior mBottomSheetBehavior;
#OnClick(R.id.sheet_done)
public void onClick(View view) {
switch (view.getId()) {
case R.id.sheet_done:
mBottomSheetBehavior.setState(BottomSheetBehavior.STATE_COLLAPSED);
break;
}
}
#Override
protected void onCreate(#Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.layout_trips_activity);
ButterKnife.bind(this);
mBottomSheetBehavior = BottomSheetBehavior.from(view);
mBottomSheetBehavior.setState(BottomSheetBehavior.STATE_HIDDEN);
mBottomSheetBehavior.setPeekHeight(0);
mBottomSheetBehavior.setBottomSheetCallback(callback);
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
if (item.getItemId() == android.R.id.home) {
if (mBottomSheetBehavior.getState() == BottomSheetBehavior.STATE_EXPANDED)
mBottomSheetBehavior.setState(BottomSheetBehavior.STATE_COLLAPSED);
else
this.finish();
} else if (item.getItemId() == R.id.filterOptions)
mBottomSheetBehavior.setState(BottomSheetBehavior.STATE_EXPANDED);
return super.onOptionsItemSelected(item);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.seach_meanu, menu);
final MenuItem searchItem = menu.findItem(R.id.action_search);
searchView = (SearchView) MenuItemCompat.getActionView(searchItem);
searchView.setOnQueryTextListener(this);
return true;
}
#Override
public boolean onQueryTextSubmit(String query) {
adapter.filter(query);
return true;
}
#Override
public boolean onQueryTextChange(String newText) {
adapter.filter(newText);
return true;
}
#Override
public void onBackPressed() {
if (mBottomSheetBehavior.getState() == BottomSheetBehavior.STATE_EXPANDED)
mBottomSheetBehavior.setState(BottomSheetBehavior.STATE_COLLAPSED);
else
super.onBackPressed();
}
}
Someone can help me identify the problem. Thanks
Add this to your manifest.This issue trigered by the softkeyboard.Sadly I cant find the real source of the problem.
<activity>
android:name=..
android:windowSoftInputMode="adjustPan">
I get this from : https://stackoverflow.com/a/12956520/7202257

What's the difference between listview item and listview footer in rendering life cycle?

I have a listview contains items and footer views. Items layout works as it should, but footer's layout doesn't work like item views...
I could't understand where my fault is.
This is my item's layout xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="vertical" >
<RelativeLayout
android:id="#+id/lstCardItem"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:background="#drawable/pm_dashboard_cardshadow" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="5.33dp"
android:layout_marginLeft="11.67dp"
android:layout_marginRight="11.67dp"
android:layout_marginTop="6dp" >
<ImageView
android:id="#+id/ivCard"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentBottom="true"
android:animateLayoutChanges="true"
android:scaleType="fitXY" />
<com.controls.DynamicResizeImageView
android:id="#+id/ivCardLock"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:animateLayoutChanges="true"
android:background="#drawable/pm_dashboard_cardmask"
android:scaleType="center"
android:src="#drawable/selector_btn_dashboard_lock" />
<LinearLayout
android:id="#+id/llInfo"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentBottom="true"
android:gravity="top|right"
android:orientation="vertical"
android:paddingLeft="18dp"
android:paddingRight="18dp"
android:visibility="visible" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center|right"
android:gravity="center|right"
android:orientation="horizontal"
android:paddingBottom="4dp"
android:paddingTop="4dp" >
<TextView
android:id="#+id/tvCardBalance"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toLeftOf="#+id/tvCurrency"
android:gravity="top"
android:text="10,344"
android:textColor="#color/white"
android:textSize="18dp"
android:typeface="serif" />
<TextView
android:id="#+id/tvCurrency"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_marginLeft="3dp"
android:layout_marginTop="2dp"
android:gravity="top"
android:text="#string/global_currency"
android:textColor="#color/white"
android:textSize="10dp"
android:typeface="sans" />
<TextView
android:id="#+id/tvCardBalanceName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:text="#string/pgDashboard_lblBalanceBanner"
android:textColor="#color/white"
android:textSize="11.33dp"
android:typeface="monospace" />
</RelativeLayout>
</LinearLayout>
</RelativeLayout>
</RelativeLayout>
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/pm_dashboard_seam" />
</LinearLayout>
For my businness side lifecycle:
private void refreshCards() {
if (applyButtons != null)
DashboardFragment.this.lvCards.removeFooterView(applyButtons);
applyButtons = new LinearLayout(getActivity());
applyButtons.setTag("FOOTER");
applyButtons.setOrientation(LinearLayout.VERTICAL);
AbsListView.LayoutParams LLParams = new AbsListView.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
applyButtons.setLayoutParams(LLParams);
if (ininalCount < 32) {
View createNewCardButton = getApplyButtonView(R.string.pgDashboard_lblCreateIninalCard, R.drawable.pm_dashboard_card_yenikartolustur, R.drawable.pm_dashboard_arrow_icon, new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent intent = new Intent(getActivity(), CreateNewCardActivity.class);
startActivity(intent);
}
});
View AddCard = getApplyButtonView(R.string.pgDashboard_lblAddCard, R.drawable.pm_dashboard_card_yenikartekle, R.drawable.pm_dashboard_plus_icon, new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent intent = new Intent(getActivity(), AddCardActivity.class);
startActivity(intent);
}
});
applyButtons.addView(createNewCardButton);
applyButtons.addView(AddCard);
}
final View applyIngCard = getApplyButtonView(R.string.pgDashboard_lblApplyToIngCard, R.drawable.pm_dashboard_card_orange, R.drawable.pm_dashboard_arrow_icon, new View.OnClickListener() {
#Override
public void onClick(View v) {
CardApplicationActivity.Synchronizer.synchronize((BaseActivity) getActivity(), new OnSyncCompletedListener() {
#Override
public void onSyncCompleted() {
Intent intent = new Intent(getActivity(), CardApplicationActivity.class);
startActivity(intent);
}
});
}
});
applyButtons.addView(applyIngCard);
View view = new View(getActivity());
view.setLayoutParams(new AbsListView.LayoutParams(AbsListView.LayoutParams.MATCH_PARENT, (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 20, getResources().getDisplayMetrics())));
view.setBackgroundResource(getResources().getColor(R.color.transparent));
applyButtons.addView(view);
bindAdapter();
}
private View getApplyButtonView(int stringId, int backgroundId, int iconId, View.OnClickListener onClickListener) {
final View view = inflater.inflate(R.layout.dashboard_list_card_item, null);
return view;
}
public void bindAdapter() {
if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB)
DashboardFragment.this.lvCards.setLayoutTransition(new LayoutTransition());
DashboardFragment.this.lvCards.addFooterView(applyButtons, null, false);
if (adapter == null) {
adapter = new CardListAdapter(getActivity(), R.layout.dashboard_list_card_item, productModelContainerList);
controller = new CardListController(lvCards);
lvCards.setDropListener(this);
controller.setDragInitMode(CardListController.ON_LONG_PRESS);
lvCards.setFloatViewManager(controller);
lvCards.setOnTouchListener(controller);
lvCards.setAdapter(adapter);
}
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.HONEYCOMB) {
DashboardFragment.this.lvCards.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
DashboardFragment.this.lvCards.setLayoutTransition(null);
}
}
Here i made some changes,, use these and let me know... otherwise i need your drawable resources to set this.
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="vertical" >
<RelativeLayout
android:id="#+id/lstCardItem"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:background="#color/background_holo_dark" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="5.33dp"
android:layout_marginLeft="11.67dp"
android:layout_marginRight="11.67dp"
android:layout_marginTop="6dp" >
<ImageView
android:id="#+id/ivCard"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentBottom="true"
android:animateLayoutChanges="true"
android:scaleType="fitXY" />
<ImageView
android:id="#+id/ivCardLock"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:animateLayoutChanges="true"
android:background="#color/background_holo_light"
android:scaleType="center"
android:src="#color/bgColor" />
<LinearLayout
android:id="#+id/llInfo"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/cropBG"
android:gravity="top|right"
android:orientation="vertical"
android:paddingLeft="18dp"
android:paddingRight="18dp"
android:visibility="visible" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="right|center_horizontal"
android:gravity="center|right"
android:orientation="horizontal"
android:paddingBottom="4dp"
android:paddingTop="4dp" >
<TextView
android:id="#+id/tvCardBalance"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toLeftOf="#+id/tvCurrency"
android:gravity="top"
android:text="10,344"
android:textColor="#android:color/white"
android:textSize="18dp"
android:typeface="serif" />
<TextView
android:id="#+id/tvCurrency"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_marginLeft="3dp"
android:layout_marginTop="2dp"
android:gravity="top"
android:text="Currency"
android:textColor="#android:color/white"
android:textSize="10dp"
android:typeface="sans" />
<TextView
android:id="#+id/tvCardBalanceName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:text="pgDashboard_lblBalanceBanner"
android:textColor="#android:color/white"
android:textSize="11.33dp"
android:typeface="monospace" />
</RelativeLayout>
</LinearLayout>
</RelativeLayout>
</RelativeLayout>
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/bottom_btn_bg_color" />
</LinearLayout>

How Can I put an Image on another Image that i am taking from you tube?

Problem is that I am taking thumbnail from Youtube of the video and when I am clicking on that Image that is redirecting me to Youtube but problem is that i want to show the image of a play Icon on that Image that I am taking from Youtube..Hope so u have Understood what I am asking.
can any One Help me.
package com.dotocto.ipartner;
import java.util.ArrayList;
import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import com.dotocto.ipartner.dataset.VedioDataSet;
import com.dotocto.ipartner.netio.WebServices;
import com.dotocto.ipartner.patten.ImageLoader;
import com.dotocto.ipartner.patten.UtilClassForValidations;
public class VideoScreen extends Activity implements OnClickListener {
private ImageView[] images;
private ImageLoader imageloader;
//private ImageView imageView;
private TextView vedio_text;
private LinearLayout image_layout;
ArrayList<VedioDataSet> imageslist;
ImageView i11;
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.video_screen);
try{
vedio_text = (TextView)findViewById(R.id.vedio_text);
image_layout = (LinearLayout)findViewById(R.id.image_layout);
imageloader = new ImageLoader(VideoScreen.this);
imageslist = new ArrayList<VedioDataSet>();
i11= (ImageView) findViewById(R.id.imageView1);
}catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}
}
#Override
protected void onStart() {
// TODO Auto-generated method stub
super.onStart();
try{
LinearLayout vedio_lay = (LinearLayout) findViewById(R.id.vedio_lay);
vedio_lay.setBackgroundResource(R.drawable.selected);
vedio_text .setTextColor(android.graphics.Color.BLUE);
if(imageslist == null || imageslist.size() <= 0)
{
new PostDataToServer().execute();
}
}catch (Exception e) {
// TODO: handle exception
}
}
class PostDataToServer extends AsyncTask<String, Integer, ArrayList<VedioDataSet>> {
#Override
protected ArrayList<VedioDataSet> doInBackground(String... arg0)
{
return WebServices.VedioActivity();
}
#Override
protected void onPostExecute(ArrayList<VedioDataSet > result)//onPostExecute(Result), invoked on the UI thread after the background computation finishes. The result of the background computation is passed to this step as a parameter.
{
// TODO Auto-generated method stub
super.onPostExecute(result);
// if(pd != null && pd.isShowing())
// pd.dismiss();
try{
if(result != null)
{
if(result.get(0).getStatus().equalsIgnoreCase("success"))
{
imageslist = result;
for(int j=0; j<imageslist.size(); j++)
{
LinearLayout hlinearlayout = new LinearLayout(VideoScreen.this);
hlinearlayout.setOrientation(LinearLayout.HORIZONTAL);
LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.WRAP_CONTENT,
1f);
hlinearlayout.setWeightSum(3);
final VedioDataSet record1 = imageslist.get(j);
ImageView img1 = new ImageView(VideoScreen.this);
LinearLayout.LayoutParams params1 = layoutParams;
params1.weight = 1f;
params1.setMargins(2, 2, 2, 2);
img1.setLayoutParams(params1);
img1.setVisibility(View.VISIBLE);
img1.setTag(record1.getYoutubeimg());
//i11.setVisibility(View.VISIBLE);
imageloader.DisplayImage(record1.getYoutubeimg(), VideoScreen.this, img1);
hlinearlayout.addView(img1);
playVideo(img1,record1);
j ++;
if(j < imageslist.size())
{
final VedioDataSet record2 = imageslist.get(j);
ImageView img2 = new ImageView(VideoScreen.this);
LinearLayout.LayoutParams params2 = layoutParams;
params2.weight = 1f;
params2.setMargins(2, 2, 2, 2);
img2.setLayoutParams(params2);
img2.setVisibility(View.VISIBLE);
img2.setTag(record2.getYoutubeimg());
imageloader.DisplayImage(record2.getYoutubeimg(), VideoScreen.this, img2);
hlinearlayout.addView(img2);
playVideo(img2,record2);
}
j++;
if(j < imageslist.size())
{
final VedioDataSet record3 = imageslist.get(j);
ImageView img3 = new ImageView(VideoScreen.this);
LinearLayout.LayoutParams params3 = layoutParams;
params3.weight = 1f;
params3.setMargins(2, 2, 2, 2);
img3.setLayoutParams(params3);
img3.setVisibility(View.VISIBLE);
img3.setTag(record3.getYoutubeimg());
imageloader.DisplayImage(record3.getYoutubeimg(), VideoScreen.this, img3);
hlinearlayout.addView(img3);
playVideo(img3,record3);
}
image_layout.addView(hlinearlayout);
}
}
else
UtilClassForValidations.alatMassageBox(VideoScreen.this,result.get(0).getErrormsg() );
}
else
UtilClassForValidations.alatMassageBox(VideoScreen.this, "We're sorry! There has been some error " +
"occured during serching video screen images and vedios. Please try again after some time.");
}
catch (Exception e)
{
// TODO: handle exception
e.printStackTrace();
}
}
}
public void playVideo(ImageView x ,final VedioDataSet y){
x.setOnClickListener(new OnClickListener()
{
#Override
public void onClick(View v)
{
try
{
if(y.getVideourl() != null && y.getVideourl().length() >0)
{
Uri uri = Uri.parse(y.getVideourl());
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
startActivity(intent);
// finish();
}
else
{
UtilClassForValidations.alatMassageBox(VideoScreen.this, "We're sorry! " +
" The video Url is can not provided by server side" +
" Please try again after some time.");
}
}
catch (Exception e)
{
// TODO: handle exception
e.printStackTrace();
}
}
});
}
public void onClick(View v) {
// TODO Auto-generated method stub
switch (v.getId())
{
case R.id.give_icon:
Intent give = new Intent(VideoScreen.this, PaymentActivity.class);
give.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
startActivity(give);
// finish();
break;
case R.id.blog_icon:
Intent blog = new Intent(VideoScreen.this, BlogActivity.class);
blog.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
startActivity(blog);
// finish();
break;
case R.id.arms_icon:
Intent vedio = new Intent(VideoScreen.this, PartnershipArms.class);
vedio.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
startActivity(vedio);
// finish();
break;
case R.id.icon_contact:
Intent contact = new Intent(VideoScreen.this, ContactUsActivity.class);
contact.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
startActivity(contact);
// finish(;
break;
}
}
}
// this is my XML
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/inner_bg"
android:orientation="vertical" >
<RelativeLayout
android:id="#+id/header_bar"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#drawable/bottom_bg" >
<TextView
android:id="#+id/header_bar_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text="VIDEOS"
android:textColor="#ffffff"
android:textSize="20sp"
android:typeface="normal" />
</RelativeLayout>
<ScrollView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_above="#+id/linearLayout"
android:layout_below="#+id/header_bar"
android:layout_centerHorizontal="true"
android:scrollbars="none" >
<LinearLayout
android:id="#+id/image_layout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<LinearLayout
android:id="#+id/image_ineerlayout2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:gravity="center"
android:orientation="horizontal"
android:weightSum="3" >
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
>
<ImageView
android:id="#+id/par_arm3"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:clickable="true"
android:src="#drawable/bottom_bg"
/>"
<ImageView
android:id="#+id/imageView1"
android:layout_width="25dp"
android:layout_height="25dp"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:layout_weight="1"
android:src="#drawable/play_btn1"
android:keepScreenOn="true"
android:clickable="true"/>
</FrameLayout>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
>
<ImageView
android:id="#+id/par_arm4"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="5dp"
android:layout_weight="1"
android:clickable="true"
android:src="#drawable/logo_holder" />
<ImageView
android:id="#+id/imageView2"
android:layout_width="25dp"
android:layout_height="25dp"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:layout_weight="1"
android:src="#drawable/play_btn1"
android:keepScreenOn="true"/>
</RelativeLayout>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
>
<ImageView
android:id="#+id/par_arm5"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="5dp"
android:layout_weight="1"
android:clickable="true"
android:src="#drawable/logo_holder" />
<ImageView
android:id="#+id/imageView3"
android:layout_width="25dp"
android:layout_height="25dp"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:layout_weight="1"
android:src="#drawable/play_btn1" />
</RelativeLayout>
</LinearLayout>
<LinearLayout
android:id="#+id/image_ineerlayout3"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_weight="3"
android:gravity="center"
android:orientation="horizontal" >
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
>
<ImageView
android:id="#+id/par_arm6"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:clickable="true"
android:src="#drawable/logo_holder" />
<ImageView
android:id="#+id/imageView4"
android:layout_width="25dp"
android:layout_height="25dp"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:layout_weight="1"
android:src="#drawable/play_btn1" />
</RelativeLayout>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
>
<ImageView
android:id="#+id/par_arm7"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="5dp"
android:layout_weight="1"
android:clickable="true"
android:src="#drawable/logo_holder" />
<ImageView
android:id="#+id/imageView6"
android:layout_width="25dp"
android:layout_height="25dp"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:layout_weight="1"
android:src="#drawable/play_btn1" />
</RelativeLayout>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
>
<ImageView
android:id="#+id/par_arm8"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="5dp"
android:layout_weight="1"
android:clickable="true"
android:src="#drawable/logo_holder" />
<ImageView
android:id="#+id/imageView5"
android:layout_width="25dp"
android:layout_height="25dp"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:layout_weight="1"
android:src="#drawable/play_btn1" />
</RelativeLayout>
</LinearLayout>
<LinearLayout
android:id="#+id/image_ineerlayout4"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_weight="3"
android:gravity="center"
android:orientation="horizontal" >
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
>
<ImageView
android:id="#+id/par_arm9"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:clickable="true"
android:src="#drawable/logo_holder" />
<ImageView
android:id="#+id/imageView7"
android:layout_width="25dp"
android:layout_height="25dp"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:layout_weight="1"
android:src="#drawable/play_btn1" />
</RelativeLayout>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
>
<ImageView
android:id="#+id/par_arm10"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="5dp"
android:layout_weight="1"
android:clickable="true"
android:src="#drawable/logo_holder" />
<ImageView
android:id="#+id/imageView88"
android:layout_width="25dp"
android:layout_height="25dp"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:layout_weight="1"
android:src="#drawable/play_btn1"
android:keepScreenOn="true" />
</RelativeLayout>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
>
<ImageView
android:id="#+id/par_arm11"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="5dp"
android:layout_weight="1"
android:clickable="true"
android:src="#drawable/logo_holder" />
<ImageView
android:id="#+id/imageView77"
android:layout_width="25dp"
android:layout_height="25dp"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:layout_weight="1"
android:src="#drawable/play_btn1"
android:keepScreenOn="true"/>
</RelativeLayout>
</LinearLayout>
</LinearLayout>
</ScrollView>
<LinearLayout
android:id="#+id/linearLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="#drawable/bottom_bg"
android:orientation="vertical" >
<LinearLayout
android:id="#+id/bott_iner_linearLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center_horizontal|center_vertical"
android:layout_marginTop="12dp"
android:gravity="center"
android:orientation="horizontal" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:orientation="vertical" >
<com.dotocto.ipartner.patten.SAutoBgButton
android:id="#+id/arms_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="6dp"
android:background="#drawable/arms_icon"
android:onClick="onClick" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="2dp"
android:text="ARMS"
android:textColor="#ffffff"
android:textSize="14sp"
android:typeface="normal" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="15dp"
android:orientation="vertical" >
<com.dotocto.ipartner.patten.SAutoBgButton
android:id="#+id/give_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="2dp"
android:background="#drawable/give_icon"
android:onClick="onClick" />
<TextView
android:id="#+id/give_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="GIVE"
android:textColor="#ffffff"
android:textSize="14sp"
android:typeface="normal" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="15dp"
android:orientation="vertical" >
<com.dotocto.ipartner.patten.SAutoBgButton
android:id="#+id/blog_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="6dp"
android:background="#drawable/blog_icon"
android:onClick="onClick" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="3dp"
android:text="BLOG"
android:textColor="#ffffff"
android:textSize="14sp"
android:typeface="normal" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="15dp"
android:orientation="vertical" >
<com.dotocto.ipartner.patten.SAutoBgButton
android:id="#+id/vedio_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="6dp"
android:layout_marginTop="2dp"
android:background="#drawable/vedio_icon"
android:onClick="onClick" />
<TextView
android:id="#+id/vedio_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="3dp"
android:text="VIDEO"
android:textColor="#ffffff"
android:textSize="14sp"
android:typeface="normal" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:orientation="vertical" >
<com.dotocto.ipartner.patten.SAutoBgButton
android:id="#+id/icon_contact"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="25dp"
android:background="#drawable/icon_contact"
android:onClick="onClick" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="5dp"
android:layout_marginTop="2dp"
android:text="CONTACT US"
android:textColor="#ffffff"
android:textSize="14sp"
android:typeface="normal" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
</RelativeLayout>
to use overlapping images in layout you can use frame layout http://developer.android.com/reference/android/widget/FrameLayout.html

Categories

Resources