When app works fine
When app not shows textviews(its finding a sensor. When cant find, giving info on textview like 'didnt found')
I created a pedometer app. It was working well on my emulator and my own android device. But when ı publish that app my friends said textviews are invisible. I examined that problem in code but didnt found a problem. Textviews are getting their text from sensor. Writing steps and calories, after some calculating. Why that problem showed up? What is the source of this problem? Why is this happening?
<RelativeLayout 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"
xmlns:app="http://schemas.android.com/apk/res-auto"
tools:context="com.mbkdev.fragments.CountStepFragment"
android:background="#211D44"
><androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_constraintBottom_toTopOf="#+id/bottomNavigationView"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" >
<Button
android:id="#+id/btnstop"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginRight="8dp"
android:background="#drawable/roundedbtn"
android:text="Durdur"
android:textAllCaps="false"
android:textColor="#EBE9F1"
android:textSize="15sp"
android:textStyle="italic"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.781"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.184" />
<Button
android:id="#+id/btnstart"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/roundedbtn"
android:gravity="center"
android:text="Başlat"
android:textAllCaps="false"
android:textColor="#EBE9F1"
android:textSize="15sp"
android:textStyle="italic"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="#+id/btnstop"
app:layout_constraintHorizontal_bias="0.472"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.184" /></androidx.constraintlayout.widget.ConstraintLayout>
<TextView
android:id="#+id/txtStepCount"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#48B9AC"
android:layout_centerInParent="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/txtStepCount"
android:layout_margin="10dp"
android:textColor="#48B9AC"
android:layout_centerHorizontal="true"
android:text="Hedef: 10.000"
/>
<ProgressBar
android:id="#+id/progress_circular"
android:layout_width="250dp"
android:layout_height="250dp"
android:layout_centerInParent="true"
android:layout_gravity="center"
android:layout_marginTop="65dp"
android:indeterminateOnly="false"
android:progressDrawable="#drawable/circle"
android:rotation="-90"
tools:progress="60" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="200dp"
android:layout_below="#+id/progress_circular"
android:gravity="center"
android:orientation="horizontal"
>
<ImageView
android:id="#+id/imageView2"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_weight="1"
android:src="#drawable/cal"
android:layout_marginBottom="45dp"
android:layout_marginLeft="12dp"
/>
<ImageView
android:id="#+id/imageView3"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_weight="1"
android:src="#drawable/distance"
android:layout_marginRight="21dp"
android:layout_marginBottom="45dp"
android:layout_marginHorizontal="10dp"
/>
<ImageView
android:id="#+id/imageView"
android:layout_width="50dp"
android:layout_height="50dp"
android:src="#drawable/steps"
android:layout_weight="1"
android:layout_marginRight="15dp"
android:layout_marginBottom="45dp"
/>
</LinearLayout>
<LinearLayout
android:id="#+id/txtlinear"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/progress_circular"
android:gravity="center"
android:orientation="horizontal"
android:layout_marginTop="85dp"
>
<TextView
android:id="#+id/txtcalori_info"
android:layout_width="wrap_content"
android:layout_height="50dp"
android:text="Kalori: "
android:textSize="16sp"
android:textColor="#48B9AC"
android:layout_weight="1"
android:textStyle="italic"
android:layout_marginLeft="12dp"
android:layout_centerHorizontal="true"
android:layout_toLeftOf="#+id/txtdistanceinfo"
android:layout_below="#+id/progress_circular"
android:gravity="center_horizontal"
/>
<TextView
android:id="#+id/txtdistanceinfo"
android:layout_width="wrap_content"
android:layout_height="50dp"
android:textColor="#48B9AC"
android:layout_below="#+id/progress_circular"
android:layout_centerHorizontal="true"
android:gravity="center_horizontal"
android:layout_weight="1"
android:text="Mesafe: "
android:textSize="16sp"
android:textStyle="italic" />
<TextView
android:id="#+id/txtstepinfo"
android:layout_width="wrap_content"
android:layout_height="50dp"
android:gravity="center_horizontal"
android:layout_below="#+id/progress_circular"
android:layout_marginRight="12dp"
android:textColor="#48B9AC"
android:layout_weight="1"
android:layout_toRightOf="#+id/txtdistanceinfo"
android:text="Adım: "
android:textSize="16sp"
android:textStyle="italic" />
</LinearLayout>
My StepCounterFragment:
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
view = inflater.inflate(R.layout.fragment_count_step,container,false);
getActivity().getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
View view = inflater.inflate(R.layout.fragment_count_step, container, false);
textView = view.findViewById(R.id.txtStepCount);
txtstepinfo = view.findViewById(R.id.txtstepinfo);
txtcalinfo = view.findViewById(R.id.txtcalori_info);
txtDistanceinfo = view.findViewById(R.id.txtdistanceinfo);
btnStart = view.findViewById(R.id.btnstart);
btnStop = view.findViewById(R.id.btnstop);
progressBar = view.findViewById(R.id.progress_circular);
progressBar.setMax(10000);
btnStart.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
startService();
}
});
btnStop.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
getActivity().stopService(new Intent(getActivity(), StepCountService.class));
}
});
sharedPreferences = getActivity().getSharedPreferences("KEY", Context.MODE_PRIVATE);
editor = sharedPreferences.edit();
sensorManager = (SensorManager) getActivity().getSystemService(SENSOR_SERVICE);
if(sensorManager.getDefaultSensor(Sensor.TYPE_STEP_COUNTER) != null){
stepCounter = sensorManager.getDefaultSensor(Sensor.TYPE_STEP_COUNTER);
isCounterSensorPresent = true;
}
else{
textView.setText("Bulunamadı");
isCounterSensorPresent = false ;
}
System.out.println(stepCount);
return view;
}
#Override
public void onSensorChanged(SensorEvent sensorEvent) {
if (sensorEvent.sensor == stepCounter){
stepCount = (int) sensorEvent.values[0];
////////////////
saveSteps();
resetStep();
int stepNumb = sharedPreferences.getInt("step",0);
////////////////
progressBar.setProgress(stepNumb);
textView.setText(String.valueOf(stepNumb));
txtstepinfo.setText("Adım: " + String.valueOf(stepNumb) );
///////////
progressBar.setProgress(stepNumb);
Log.i("sda",String.valueOf(stepCount));
/////////////////////
txtcalinfo.setText("Kalori: "+calculateCalori(stepNumb));
txtDistanceinfo.setText("Mesafe: "+calculateDistance(stepNumb));
}
}
I think it's not one of programmatic issue and could be your listview went up to bottom on screen. You could research How to develop an android application for different device sizes. Visit here https://developer.android.com/training/multiscreen/screensizes
I found what is the problem. I was forgetting the add user permissions.
I Added to the Manifest.xml:
<uses-permission android:name="android.permission.ACTIVITY_RECOGNITION"/>
onCreate Method:
if(ContextCompat.checkSelfPermission(this,
Manifest.permission.ACTIVITY_RECOGNITION) == PackageManager.PERMISSION_DENIED){
//ask for permission
requestPermissions(new String[]{Manifest.permission.ACTIVITY_RECOGNITION}, PHYISCAL_ACTIVITY);
}
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>
I want to continuously show different text on text view which animates from left to right, waits on the center of the screen for 3 sec and animates outside of the screen and replaced by a new text which animates from left to right
I have included a textview inside a viewflipper.
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="#+id/tv__inc_pre_sing__screen_title"
android:layout_width="match_parent"
android:layout_height="50dp"
android:background="#fff"
android:gravity="center"
android:text="PRACTICE"
android:textAllCaps="true"
android:textColor="#color/colorAccent"
android:textSize="16dp"
android:textStyle="bold"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<android.support.constraint.ConstraintLayout
android:id="#+id/rl__inc_pre_sing__tm_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:animateLayoutChanges="true"
android:background="#efff"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#id/tv__inc_pre_sing__screen_title">
<ImageView
android:id="#+id/tv__inc_pre_sing__quotation_mark"
android:layout_width="12dp"
android:layout_height="12dp"
android:layout_marginTop="12dp"
android:src="#drawable/ic_launcher_background"
app:layout_constraintTop_toTopOf="parent" />
<ViewFlipper
android:id="#+id/view_flipper"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:animateLayoutChanges="true"
android:layout_marginStart="24dp"
android:layout_marginTop="16dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="#id/tv__inc_pre_sing__quotation_mark"
app:layout_constraintTop_toTopOf="parent">
<TextView
android:id="#+id/tv"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="Hiiiiii" />
</ViewFlipper>
<ImageView
android:layout_width="12dp"
android:layout_height="12dp"
android:layout_marginBottom="8dp"
android:layout_marginTop="8dp"
android:src="#drawable/ic_launcher_background"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#id/view_flipper" />
</android.support.constraint.ConstraintLayout>
<Button
android:id="#+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:text="Click Me"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />
<View
android:layout_width="0dp"
android:layout_height="16dp"
android:background="#drawable/ic_launcher_background"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#id/rl__inc_pre_sing__tm_container" />
</android.support.constraint.ConstraintLayout>
MainActivity Code
public class Main6Activity extends AppCompatActivity {
private ViewFlipper mViewFlipper;
private int count = 0;
private TextView textView;
private ConstraintLayout rootContainer;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main6);
mViewFlipper = findViewById(R.id.view_flipper);
textView = findViewById(R.id.tv);
rootContainer = findViewById(R.id.rl__inc_pre_sing__tm_container);
mViewFlipper.setAutoStart(true);
mViewFlipper.startFlipping();
mViewFlipper.setInAnimation(AnimationUtils.loadAnimation(rootContainer.getContext(), android.R.anim.slide_in_left));
mViewFlipper.setOutAnimation(AnimationUtils.loadAnimation(rootContainer.getContext(), android.R.anim.slide_out_right));
Resources resources = getApplicationContext().getResources();
final String[] textString = resources.getStringArray(R.array.teacher_messages);
new Thread() {
#Override
public void run() {
super.run();
try {
while (!isInterrupted()) {
Thread.sleep(3000);
runOnUiThread(() -> updateText(textString));
}
} catch (Exception e) {
e.printStackTrace();
}
}
}.start();
}
public void updateText(String[] strings) {
if (count >= strings.length) {
count = 0;
}
textView.setText(strings[count]);
count++;
}
}
I guess the outanimation does not work as the textview length changes and I want to animate the constraint layout according to the textview height.
Not sure if this is the right reason.
The outAnimation of the view flipper does not work.
That's not how ViewFlipper works . the View flipper will only animate the view added to it .
Here's an example :
<ViewFlipper
android:id="#+id/viewFlipper"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/loading"
android:autoStart="true"
android:flipInterval="5000"
android:inAnimation="#android:anim/slide_in_left"
android:outAnimation="#android:anim/slide_out_right">
<TextView
fontPath="fonts/benton_light.ttf"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="#string/text1"
android:textColor="#color/white"
android:textSize="18sp" />
<TextView
fontPath="fonts/benton_light.ttf"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="#string/text3"
android:textColor="#color/white"
android:textSize="18sp" />
<TextView
fontPath="fonts/benton_light.ttf"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="#string/tex2"
android:textColor="#color/white"
android:textSize="18sp" />
</ViewFlipper>
Source
If that does not suit your needs . you can take a look at this solution. (Animating text changes in a TextView)
I want to make a simple Sudoku game in which i want to create 3*3 matrix.I created a matrix but i getting problem how to insert some value at specific position in Grid Layout.Please can anyone help me.
I have done up to this so far...
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mScrollView = (ScrollView) findViewById(R.id.scroll_view);
mScrollView.setSmoothScrollingEnabled(true);
mGrid = (GridLayout) findViewById(R.id.grid_layout);
// mGrid.setOnDragListener(new DragListener());
final LayoutInflater inflater = LayoutInflater.from(this);
for (int i = 0; i < NBR_ITEMS; i++) {
final View itemView = inflater.inflate(R.layout.item_grid, mGrid, false);
final TextView text = (TextView) itemView.findViewById(R.id.text);
if ((i == 4)) {
text.setText("3");
}
if ((i == 2)) {
text.setText("2");
}
if ((i == 7)) {
text.setText("1");
}
final int size = mGrid.getChildCount();
System.out.println("size===" + size);
itemView.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
final int index = calculateNewIndex(itemView.getX(), itemView.getY());
System.out.println("index====" + index);
System.out.println("click on cell");
}
});
// itemView.setOnLongClickListener(new LongPressListener());
mGrid.addView(itemView);
}
}
Simply you can create 3*3 matrix using LinearLayout and do wahtever you want like this,
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
android:weightSum="1"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight=".33"
android:orientation="horizontal"
android:weightSum="1"
>
<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight=".33"
android:text="1"
android:gravity="center"
android:textSize="24sp"
/>
<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight=".33"
android:text="2"
android:gravity="center"
android:textSize="24sp"
/>
<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight=".33"
android:text="3"
android:gravity="center"
android:textSize="24sp"
/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight=".33"
android:orientation="horizontal"
android:weightSum="1"
>
<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight=".33"
android:text="4"
android:gravity="center"
android:textSize="24sp"
/>
<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight=".33"
android:text="5"
android:gravity="center"
android:textSize="24sp"
/>
<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight=".33"
android:text="6"
android:gravity="center"
android:textSize="24sp"
/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight=".33"
android:orientation="horizontal"
android:weightSum="1"
>
<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight=".33"
android:text="7"
android:gravity="center"
android:textSize="24sp"
/>
<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight=".33"
android:text="8"
android:gravity="center"
android:textSize="24sp"
/>
<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight=".33"
android:text="9"
android:gravity="center"
android:textSize="24sp"
/>
</LinearLayout>
</LinearLayout>
Like This
I am trying to make custom dialog in which i want to make selection of textview and image visible if user is going to selection .
in below code i have given three text views and four image view, want that if user is going to select text view or image view it should be text color change and on image it should be tick mark should be appear.
like this attached image .
attached image
As per attached image i want to make selection if user select image it should appear as a tick mark and if user selects any text views then tick should below of the text views and color also changed.
MainActivity
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final Dialog dialog = new Dialog(this);
dialog.setContentView(R.layout.cust);
dialog.setTitle("Your title");
dialog.setCancelable(false);
dialog.show();
TextView d_btn_ok = (TextView) dialog.findViewById(R.id.btnOk);
TextView d_btn_cancel = (TextView) dialog.findViewById(R.id.btnCancel);
d_btn_ok.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
dialog.dismiss();
}
});
d_btn_cancel.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
dialog.dismiss();
}
});
TextView tvMsg11 =(TextView) dialog.findViewById(R.id.tvMsg11);
TextView tvMsg111 =(TextView) dialog.findViewById(R.id.tvMsg111);
TextView tvMsg1111 =(TextView) dialog.findViewById(R.id.tvMsg1111);
ImageView image1 = (ImageView) dialog.findViewById(R.id.image1);
image1.setImageDrawable(getResources().getDrawable(R.drawable.one));
ImageView image2 = (ImageView) dialog.findViewById(R.id.image2);
image2.setImageDrawable(getResources().getDrawable(R.drawable.two));
ImageView image3 = (ImageView) dialog.findViewById(R.id.image3);
image3.setImageDrawable(getResources().getDrawable(R.drawable.three));
ImageView image4 = (ImageView) dialog.findViewById(R.id.image4);
image4.setImageDrawable(getResources().getDrawable(R.drawable.four));
}
}
cust.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="430dp"
android:orientation="vertical"
android:background="#ffffff"
android:theme="#style/AppTheme">
<TextView
android:id="#+id/tvMsg"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="24dp"
android:layout_marginLeft="20dp"
android:textSize="20sp"
android:textColor="#293448"
android:text="Update your water intake" />
<TextView
android:id="#+id/tvMsg1"
android:layout_below="#+id/tvMsg"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="25dp"
android:layout_marginLeft="21.5dp"
android:textSize="16sp"
android:textColor="#293448"
android:text="How many glasses of water do you
drink daily?" />
<LinearLayout
android:id="#+id/linearImage21"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginTop="20dp"
android:layout_below="#+id/tvMsg1"
android:weightSum="3">
<TextView
android:id="#+id/tvMsg11"
android:layout_width="wrap_content"
android:layout_weight="1"
android:layout_marginLeft="23.5dp"
android:layout_height="wrap_content"
android:text="4 Glasses"
android:textSize="14sp"/>
<TextView
android:id="#+id/tvMsg111"
android:layout_toRightOf="#+id/tvMsg11"
android:layout_width="wrap_content"
android:layout_weight="1"
android:layout_height="wrap_content"
android:text="6 Glasses"
android:textSize="14sp"/>
<TextView
android:id="#+id/tvMsg1111"
android:layout_toRightOf="#+id/tvMsg111"
android:layout_width="wrap_content"
android:layout_weight="1"
android:layout_height="wrap_content"
android:text="8 Glasses"
android:textSize="14sp"/>
</LinearLayout>
<TextView
android:id="#+id/container"
android:layout_below="#+id/linearImage21"
android:layout_marginTop="48dp"
android:layout_marginLeft="21.5dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="16sp"
android:text="Your container size?" />
<LinearLayout
android:id="#+id/linearImage1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginTop="20dp"
android:layout_below="#+id/container"
android:weightSum="4">
<ImageView
android:id="#+id/image1"
android:layout_width="0dp"
android:layout_weight="1"
android:background="#drawable/custom_button_background"
android:checked="true"
android:layout_height="wrap_content" />
<ImageView
android:id="#+id/image2"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content" />
<ImageView
android:id="#+id/image3"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content" />
<ImageView
android:id="#+id/image4"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content" />
</LinearLayout>
<!-- <LinearLayout
android:id="#+id/linearImag2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginTop="20dp"
android:layout_below="#+id/linearImage1"
android:weightSum="2">
<ImageView
android:id="#+id/image3"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content" />
<ImageView
android:id="#+id/image4"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content" />
</LinearLayout>-->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/linearImage1"
android:orientation="horizontal"
android:layout_marginTop="28dp"
android:weightSum="2"
>
<TextView
android:id="#+id/btnOk"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="#fff"
android:layout_marginLeft="86.5dp"
android:textSize="16sp"
android:text="CANCEL"
android:textAllCaps="true"
android:textColor="#293448" />
<TextView
android:id="#+id/btnCancel"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_marginLeft="48.5dp"
android:layout_weight="1"
android:textSize="16sp"
android:layout_marginRight="6dp"
android:background="#fff"
android:text="SUBMIT"
android:textAllCaps="true"
android:textColor="#21c8d7" />
</LinearLayout>
</RelativeLayout>
After apply above code
I am getting like this image
this image
We can do it easily as per attached image
Made visible when need of Highlighter under text views or adjacent of image.
or Made invisible when not need or pressed That's it .
Wrote code for same which is working .
text color change on the basis of text selection :
text_color.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true" android:color="#00b200"></item>
<item android:state_focused="true" android:color="#00b200"/>
<item android:state_selected="true" android:color="#000000"/>
<item android:color="#d3d3d3"></item>
</selector>
For Dialog :-
final Dialog dialog = new Dialog(this);
dialog.setContentView(R.layout.cust);
dialog.setTitle("Your title");
dialog.setCancelable(false);
dialog.show();
TextView d_btn_ok = (TextView) dialog.findViewById(R.id.btnOk);
TextView d_btn_cancel = (TextView) dialog.findViewById(R.id.btnCancel);
d_btn_ok.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
dialog.dismiss();
}
});
d_btn_cancel.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
dialog.dismiss();
}
});
final TextView tvMsg111 =(TextView) dialog.findViewById(R.id.tvMsg111);
final TextView tvMsg1111=(TextView) dialog.findViewById(R.id.tvMsg1111);
final TextView tvMsg11 = (TextView) dialog.findViewById(R.id.tvMsg11);
ImageView tick5=(ImageView) dialog.findViewById(R.id.tick5);
ImageView tick6=(ImageView) dialog.findViewById(R.id.tick6);
ImageView tick7=(ImageView) dialog.findViewById(R.id.tick7);
tvMsg11.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
// final ImageView imageView = (ImageView) dialog.findViewById(R.id.image2);
//tvMsg11.setImageDrawable(getResources().getDrawable(R.drawable.tick));
tvMsg111.setSelected(false);
tvMsg1111.setSelected(false);
tvMsg11.setSelected(true);
tick5.setVisibility(View.VISIBLE);
tick6.setVisibility(View.INVISIBLE);
tick7.setVisibility(View.INVISIBLE);
}
});
// final TextView tvMsg111 =(TextView) dialog.findViewById(R.id.tvMsg111);
tvMsg111.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
tvMsg11.setSelected(false);
tvMsg1111.setSelected(false);
tvMsg111.setSelected(true);
tick6.setVisibility(View.VISIBLE);
tick7.setVisibility(View.INVISIBLE);
tick5.setVisibility(View.INVISIBLE);
}
});
//final TextView tvMsg1111 =(TextView) dialog.findViewById(R.id.tvMsg1111);
tvMsg1111.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
tvMsg11.setSelected(false);
tvMsg111.setSelected(false);
tvMsg1111.setSelected(true);
tick7.setVisibility(View.VISIBLE);
tick6.setVisibility(View.INVISIBLE);
tick5.setVisibility(View.INVISIBLE);
}
});
/*TextView tvMsg111 =(TextView) dialog.findViewById(R.id.tvMsg111);
TextView tvMsg1111 =(TextView) dialog.findViewById(R.id.tvMsg1111);*/
ImageView image1 = (ImageView) dialog.findViewById(R.id.image1);
ImageView tick1=(ImageView)dialog.findViewById(R.id.tick1);
ImageView tick2=(ImageView)dialog.findViewById(R.id.tick2);
ImageView tick3=(ImageView)dialog.findViewById(R.id.tick3);
ImageView tick4=(ImageView)dialog.findViewById(R.id.tick4);
image1.setImageDrawable(getResources().getDrawable(R.drawable.one));
image1.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
//final ImageView imageView = (ImageView) dialog.findViewById(R.id.image2);
tick1.setVisibility(View.VISIBLE);
tick2.setVisibility(View.INVISIBLE);
tick3.setVisibility(View.INVISIBLE);
tick4.setVisibility(View.INVISIBLE);
/* imageView.setImageDrawable(getResources().getDrawable(R.drawable.tick));
imageView.setImageDrawable(getResources().getDrawable(R.drawable.two));*/
}
});
ImageView image2 = (ImageView) dialog.findViewById(R.id.image2);
// ImageView image21 = (ImageView) dialog.findViewById(R.drawable.four);
// for replacing image on click of image
image2.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
//final ImageView imageView = (ImageView) dialog.findViewById(R.id.image2);
tick2.setVisibility(View.VISIBLE);
tick1.setVisibility(View.INVISIBLE);
tick3.setVisibility(View.INVISIBLE);
tick4.setVisibility(View.INVISIBLE);
/* imageView.setImageDrawable(getResources().getDrawable(R.drawable.tick));
imageView.setImageDrawable(getResources().getDrawable(R.drawable.two));*/
}
});
image2.setImageDrawable(getResources().getDrawable(R.drawable.two));
ImageView image3 = (ImageView) dialog.findViewById(R.id.image3);
image3.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
//final ImageView imageView = (ImageView) dialog.findViewById(R.id.image2);
tick3.setVisibility(View.VISIBLE);
tick1.setVisibility(View.INVISIBLE);
tick2.setVisibility(View.INVISIBLE);
tick4.setVisibility(View.INVISIBLE);
/* imageView.setImageDrawable(getResources().getDrawable(R.drawable.tick));
imageView.setImageDrawable(getResources().getDrawable(R.drawable.two));*/
}
});
image3.setImageDrawable(getResources().getDrawable(R.drawable.three));
ImageView image4 = (ImageView) dialog.findViewById(R.id.image4);
image4.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
//final ImageView imageView = (ImageView) dialog.findViewById(R.id.image2);
tick4.setVisibility(View.VISIBLE);
tick1.setVisibility(View.INVISIBLE);
tick2.setVisibility(View.INVISIBLE);
tick3.setVisibility(View.INVISIBLE);
/* imageView.setImageDrawable(getResources().getDrawable(R.drawable.tick));
imageView.setImageDrawable(getResources().getDrawable(R.drawable.two));*/
}
});
image4.setImageDrawable(getResources().getDrawable(R.drawable.four));
cust.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="430dp"
android:orientation="vertical"
android:background="#ffffff"
android:theme="#style/AppTheme">
<TextView
android:id="#+id/tvMsg"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="24dp"
android:layout_marginLeft="20dp"
android:textSize="20sp"
android:textColor="#293448"
android:text="Update your water intake" />
<TextView
android:id="#+id/tvMsg1"
android:layout_below="#+id/tvMsg"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="25dp"
android:layout_marginLeft="21.5dp"
android:textSize="16sp"
android:textColor="#293448"
android:text="How many glasses of water do you
drink daily?" />
<LinearLayout
android:id="#+id/linearImage21"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginTop="20dp"
android:layout_below="#+id/tvMsg1"
android:weightSum="3">
<TextView
android:id="#+id/tvMsg11"
android:layout_width="wrap_content"
android:layout_weight="1"
android:layout_marginLeft="23.5dp"
android:textColor="#drawable/text_color"
android:layout_height="wrap_content"
android:text="4 Glasses"
android:textSize="14sp"/>
<TextView
android:id="#+id/tvMsg111"
android:layout_toRightOf="#+id/tvMsg11"
android:layout_width="wrap_content"
android:layout_weight="1"
android:textColor="#drawable/text_color"
android:layout_marginLeft="8dp"
android:layout_height="wrap_content"
android:text="6 Glasses"
android:textSize="14sp"/>
<TextView
android:id="#+id/tvMsg1111"
android:layout_toRightOf="#+id/tvMsg111"
android:layout_width="wrap_content"
android:layout_weight="1"
android:layout_marginLeft="10dp"
android:textColor="#drawable/text_color"
android:layout_height="wrap_content"
android:text="8 Glasses"
android:textSize="14sp"/>
</LinearLayout>
<LinearLayout
android:id="#+id/lineartick"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginTop="2dp"
android:layout_below="#+id/linearImage21"
android:weightSum="3">
<ImageView
android:id="#+id/tick5"
android:layout_width="16dp"
android:layout_weight="1"
android:src="#drawable/texthiglighter"
android:visibility="invisible"
android:layout_marginRight="12dp"
android:layout_height="10dp" />
<ImageView
android:id="#+id/tick6"
android:layout_width="16dp"
android:layout_weight="0.7"
android:src="#drawable/texthiglighter"
android:visibility="invisible"
android:layout_marginLeft="1dp"
android:layout_toRightOf="#+id/image1"
android:layout_height="10dp" />
<ImageView
android:id="#+id/tick7"
android:layout_width="16dp"
android:layout_weight="1.3"
android:src="#drawable/texthiglighter"
android:visibility="invisible"
android:layout_height="10dp" />
</LinearLayout>
<TextView
android:id="#+id/container"
android:layout_below="#+id/linearImage21"
android:layout_marginTop="48dp"
android:layout_marginLeft="21.5dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="16sp"
android:textColor="#293448"
android:alpha="80"
android:text="Your container size?" />
<LinearLayout
android:id="#+id/linearImage1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginTop="20dp"
android:layout_below="#+id/container"
android:weightSum="4">
<ImageView
android:id="#+id/image1"
android:layout_width="0dp"
android:layout_weight="1"
android:checked="true"
android:layout_height="wrap_content" />
<ImageView
android:id="#+id/tick1"
android:layout_width="13dp"
android:layout_weight="0.1"
android:src="#drawable/tick"
android:layout_marginLeft="0.1dp"
android:visibility="invisible"
android:layout_toRightOf="#+id/image1"
android:layout_height="13dp" />
<ImageView
android:id="#+id/image2"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content" />
<ImageView
android:id="#+id/tick2"
android:layout_width="13dp"
android:layout_weight="0.1"
android:src="#drawable/tick"
android:layout_marginLeft="0.1dp"
android:visibility="invisible"
android:layout_toRightOf="#+id/image2"
android:layout_height="13dp" />
<ImageView
android:id="#+id/image3"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content" />
<ImageView
android:id="#+id/tick3"
android:layout_width="13dp"
android:layout_weight="0.1"
android:src="#drawable/tick"
android:layout_marginLeft="0.1dp"
android:visibility="invisible"
android:layout_toRightOf="#+id/image3"
android:layout_height="13dp" />
<ImageView
android:id="#+id/image4"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content" />
<ImageView
android:id="#+id/tick4"
android:layout_width="13dp"
android:layout_weight="0.1"
android:src="#drawable/tick"
android:layout_marginLeft="0.1dp"
android:visibility="invisible"
android:layout_marginRight="25dp"
android:layout_toRightOf="#+id/image4"
android:layout_height="13dp" />
</LinearLayout>
<LinearLayout
android:id="#+id/linearscale"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginTop="16dp"
android:layout_below="#+id/linearImage1"
android:weightSum="4">
<TextView
android:id="#+id/onne"
android:layout_width="wrap_content"
android:layout_weight="1"
android:layout_marginLeft="5dp"
android:textColor="#283d65"
android:layout_height="wrap_content"
android:text="150 ML"
android:textAllCaps="true"
android:textSize="14sp"/>
<TextView
android:id="#+id/twoe"
android:layout_width="wrap_content"
android:layout_weight="1"
android:textColor="#283d65"
android:layout_height="wrap_content"
android:text="250 ML"
android:textAllCaps="true"
android:textSize="14sp"/>
<TextView
android:id="#+id/three"
android:layout_width="wrap_content"
android:layout_weight="1"
android:textColor="#283d65"
android:layout_height="wrap_content"
android:text="500 ML"
android:textAllCaps="true"
android:textSize="14sp"/>
<TextView
android:id="#+id/foure"
android:layout_width="wrap_content"
android:layout_weight="1"
android:layout_marginRight="6dp"
android:textColor="#283d65"
android:layout_height="wrap_content"
android:text="1 LTR"
android:textAllCaps="true"
android:textSize="14sp"/>
</LinearLayout>
<View
android:id="#+id/viewp"
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginLeft="6dp"
android:layout_marginRight="6dp"
android:layout_marginTop="10dp"
android:layout_gravity="center"
android:alpha="4"
android:background="#000000"
android:layout_below="#+id/linearscale"></View>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/linearscale"
android:orientation="horizontal"
android:layout_marginTop="28dp"
android:weightSum="2"
>
<TextView
android:id="#+id/btnOk"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="#fff"
android:layout_marginLeft="86.5dp"
android:textSize="16sp"
android:text="CANCEL"
android:textAllCaps="true"
android:textColor="#293448" />
<TextView
android:id="#+id/btnCancel"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_marginLeft="48.5dp"
android:layout_weight="1"
android:textSize="16sp"
android:layout_marginRight="6dp"
android:background="#fff"
android:text="SUBMIT"
android:textAllCaps="true"
android:textColor="#21c8d7" />
</LinearLayout>
</RelativeLayout>